scroll-view-refresher.uvue 2.3 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
<script>
S
shutao 已提交
16 17 18 19 20
	export default {

		data() {
			return {
				scrollData: [] as Array <string>,
shutao-dc's avatar
shutao-dc 已提交
21 22
				refresherTriggered: false,
				refresherrefresh: false
S
shutao 已提交
23 24 25 26 27 28 29 30 31 32 33
			};
		},
		onLoad() {
			let lists: Array < string > = []
			for (let i = 0; i < 20; i++) {
				lists.push("item---"+i)
			}
			this.scrollData = lists
		},

		methods: {
shutao-dc's avatar
shutao-dc 已提交
34 35
			onRefresherrefresh(_: RefresherEvent) {
				this.refresherrefresh = true
S
shutao 已提交
36 37 38 39 40 41
				console.log("onRefresherrefresh--------------下拉刷新触发")
				this.refresherTriggered = true
				setTimeout(function(){
					this.refresherTriggered = false
				}, 1500)
				
S
shutao 已提交
42
			},
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
43
			onRefresherabort(_: RefresherEvent) {
S
shutao 已提交
44 45
				console.log("onRefresherabort------下拉刷新被中止")
			},
shutao-dc's avatar
shutao-dc 已提交
46 47
			onRefresherrestore(_: RefresherEvent) {
				this.refresherrefresh = false
S
shutao 已提交
48 49 50 51 52 53 54
				console.log("onRefresherrestore------下拉刷新被复位")
			},
			onRefresherpulling(e: RefresherEvent) {
				console.log("onRefresherrestore------拉刷新控件被下拉-dy="+e.detail.dy)
			},
			onScrolltolower(e: ScrollToLowerEvent) {
				console.log("onScrolltolower 滚动到底部-----"+e.detail.direction)
S
shutao 已提交
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 95 96
			}
		}
	};
</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>