scroll-view-refresher.uvue 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<template>
	<view class="container">
		<page-head title="scroll-view 下拉刷新"></page-head>
		<scroll-view class="scroll" refresher-enabled = true :refresher-triggered = "refresherTriggered"
		@refresherrefresh="onRefresherrefresh" @refresherabort="onRefresherabort" @refresherrestore="onRefresherrestore"
		@refresherpulling="onRefresherpulling" @scrolltolower="onScrolltolower">
			<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>
<script>
	export default {

		data() {
			return {
				scrollData: [] as Array <string>,
shutao-dc's avatar
shutao-dc 已提交
21
				refresherTriggered: false,
22 23 24 25 26 27 28 29 30 31 32 33
				refresherrefresh: false
			};
		},
		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
			onRefresherrefresh(_: RefresherEvent) {
35 36 37 38 39 40 41 42 43 44 45
				this.refresherrefresh = true
				console.log("onRefresherrefresh--------------下拉刷新触发")
				this.refresherTriggered = true
				setTimeout(() => {
					this.refresherTriggered = false
				}, 1500)

			},
			onRefresherabort(_: RefresherEvent) {
				console.log("onRefresherabort------下拉刷新被中止")
			},
shutao-dc's avatar
shutao-dc 已提交
46
			onRefresherrestore(_: RefresherEvent) {
47 48 49 50 51 52 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 95 96
				this.refresherrefresh = false
				console.log("onRefresherrestore------下拉刷新被复位")
			},
			onRefresherpulling(e: RefresherEvent) {
				console.log("onRefresherrestore------拉刷新控件被下拉-dy="+e.detail.dy)
			},
			onScrolltolower(e: ScrollToLowerEvent) {
				console.log("onScrolltolower 滚动到底部-----"+e.detail.direction)
			}
		}
	};
</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>