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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值