uni-app分页实现上拉加载

uni-app 列表进行分页,上拉的时候加载下一页,需要页面支持滚动,不适用scroll-view

<template>
	<view>
		<view class="item" v-for="(item,index) in list" :key="index">

		</view>
		<view class="loadingText">{
   
   {loadingText}}</view>
		<view v-if="list.length === 0" >
			<image class="nobodyImage" :src="'../../static/image/noBody.png'"></image>
			<view class="nobodyText">暂无记录~</view>
		</view>
	</view>
</template>

<script>
	import request from '@/common/request'
	export default {
		data() {
			return {
				page: {
					current: 1,
					size: 10,
					total: 0,
				},
				loadingText: '',
				list: []
			}
		},
		onLoad: function(option) {
			this.page.current = 1
			this.selectList()
		},
		onPullDownRefresh() {
			this.page.current = 1
			this.selectList()
		},
		onReachBottom() {
			this.getMoreList();
		},
		methods: {
			getMoreList() {
				this.loadingText = '-- 正在加载 --'
				request.get('/history/page', {
					current: this.page.current,
					pageSize: this.page.size,
				}).then(res => {

					if (res.data.list.length == 0 || res.data.list == null) {
						this.loadingText = '-- 暂无更多 --'
						return false;
					}
					var newlist = res.data.list;
					this.list = this.list.concat(newlist)
					this.page.current++;

				});
			},
			selectList() {
				request.get('/history/page', {
					current: this.page.current,
					pageSize: this.page.size,
				}).then(response => {
					this.list = response.data.list;
					this.page.total = response.data.total;
					uni.stopPullDownRefresh()
					this.page.current++;
				});
			}
		}
	}
</script>
<style>
	page {
		background-color: #F1F1F1;

	}
</style>
<style>
	.item {
		display: flex;
		flex-direction: column;
		background-color: white;
		margin-top: 32rpx;
		padding: 16rpx;
	}

	.loadingText {
		padding: 20rpx 0 40rpx 0;
		text-align: center;
		color: #310D05;
		font-size: 28rpx;
	}

	.nobodyImage {
		width: 557rpx;
		height: 300rpx;
		margin-left: 104rpx;
	}

	.nobodyText {
		font-size: 40rpx;
		color: #666666;
		text-align: center;
		margin-top: 63rpx;

	}
</style>

猜你喜欢

转载自blog.csdn.net/qq_35323539/article/details/126698219