scroll-view-refresher.uvue 2.2 KB
Newer Older
S
shutao 已提交
1 2 3
<template>
	<view class="container">
		<page-head title="scroll-view 下拉刷新"></page-head>
S
shutao 已提交
4 5 6
		<scroll-view class="scroll" refresher-enabled = true :refresher-triggered = "refresherTriggered"
		@refresherrefresh="onRefresherrefresh" @refresherabort="onRefresherabort" @refresherrestore="onRefresherrestore"
		@refresherpulling="onRefresherpulling" @scrolltolower="onScrolltolower">
S
shutao 已提交
7 8 9 10 11 12 13 14
			<view v-for="key in scrollData" :key="key">
				<view class="scroll-item">
					<text class="scroll-item-title">{{key}}</text>
				</view>
			</view>
		</scroll-view>
	</view>
</template>
S
shutao 已提交
15 16
<script>

S
shutao 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
	export default {

		data() {
			return {
				scrollData: [] as Array <string>,
				refresherTriggered: false 
			};
		},
		onLoad() {
			let lists: Array < string > = []
			for (let i = 0; i < 20; i++) {
				lists.push("item---"+i)
			}
			this.scrollData = lists
		},

		methods: {
S
shutao 已提交
34
			onRefresherrefresh(e: RefresherEvent) {
S
shutao 已提交
35 36 37 38 39 40
				console.log("onRefresherrefresh--------------下拉刷新触发")
				this.refresherTriggered = true
				setTimeout(function(){
					this.refresherTriggered = false
				}, 1500)
				
S
shutao 已提交
41 42 43 44 45 46 47 48 49 50 51 52
			},
			onRefresherabort(e: RefresherEvent) {
				console.log("onRefresherabort------下拉刷新被中止")
			},
			onRefresherrestore(e: RefresherEvent) {
				console.log("onRefresherrestore------下拉刷新被复位")
			},
			onRefresherpulling(e: RefresherEvent) {
				console.log("onRefresherrestore------拉刷新控件被下拉-dy="+e.detail.dy)
			},
			onScrolltolower(e: ScrollToLowerEvent) {
				console.log("onScrolltolower 滚动到底部-----"+e.detail.direction)
S
shutao 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
			}
		}
	};
</script>

<style>
	.container{
		display: flex;
		flex-direction: column;
		border:dashed;
		flex: 1;
	}
	
	.scroll {
		background-color: #eee;
		position: relative;
		width: 100%;
		flex: 1;
		display: flex;
		flex-direction: column;
		border-color: red;
	}
	
	.scroll-item {
	    margin-left: 12rpx;
	    margin-right: 12rpx;
	    margin-top: 12rpx;
		background-color: #fff;
	    border-radius: 8rpx;
	}
	
	.scroll-item-title {
	    width:100%;
	    height: 120rpx;
	    line-height: 120rpx;
	    text-align: center;
	    color: #555;
	}
	
	

</style>