pull-down-refresh.uvue 1.6 KB
Newer Older
1
<template>
2
	<scroll-view style="flex: 1;">
3
		<!-- 实际开发中,长列表应该使用list-view -->
4
		<view class="uni-padding-wrap uni-common-mt">
Y
yurj26 已提交
5
			<text class="text" v-for="(num,index) in data" :key="index">list - {{num}}</text>
A
Anne_LXM 已提交
6
			<view v-if="showLoadMore">{{loadMoreText}}</view>
7
		</view>
8
	</scroll-view>
9 10 11 12 13
</template>
<script lang="uts">
	export default {
		data() {
			return {
14
				data: [] as Array<number>,
15 16 17 18 19
				loadMoreText: "加载中...",
				showLoadMore: false,
				max: 0
			}
		},
20 21
		onReady() {
      uni.startPullDownRefresh();
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
			this.initData();
		},
		onReachBottom() {
			console.log("onReachBottom");
			if (this.max > 40) {
				this.loadMoreText = "没有更多数据了!"
				return;
			}
			this.showLoadMore = true;
			setTimeout(() => {
				this.setListData();
			}, 300);
		},
		onPullDownRefresh() {
			console.log('onPullDownRefresh');
			this.initData();
		},
		methods: {
			initData(){
				setTimeout(() => {
					this.max = 0;
					this.data = [];
44
					let data:Array<number> = [];
45
					this.max += 20;
46
					for (let i:number = this.max - 19; i < this.max + 1; i++) {
47 48 49 50
						data.push(i)
					}
					this.data = this.data.concat(data);
					uni.stopPullDownRefresh();
51
				}, 1000);
52 53
			},
			setListData() {
54
				let data:Array<number> = [];
55
				this.max += 10;
56
				for (let i:number = this.max - 9; i < this.max + 1; i++) {
57 58 59 60 61 62 63 64 65 66
					data.push(i)
				}
				this.data = this.data.concat(data);
			}
		}
	}
</script>

<style>
	.text {
67
		margin: 6px 0;
68 69
		width:100%;
		background-color: #fff;
70 71
		height: 52px;
		line-height: 52px;
72 73
		text-align: center;
		color: #555;
74
		border-radius: 4px;
75 76
	}
</style>