uniapp懒加载分页

前言:
最近一直在写uniapp移动端项目,在写到列表时常常会有懒加载分页的功能,那么接下来我们来进行实现懒加载分页的功能,话不多说直接上代码!

<u-cell-group>
	<u-cell-item v-for="(item,index) in cellData" :key="index" @click="goDetails(item)" :title="item.name" :arrow="true">
		<template slot="label">
			<span>{{"技术类别:"+item.type}}</span>
		</template>
	</u-cell-item>
</u-cell-group>

<u-loadmore :status="status" v-show="status != 'nomore'" :load-text="loadText"/>  //重要代码
在data中定义:
cellData: [],
status: 'loadmore',
loadText: {  //重要代码
	loadmore: '',
	loading: '',
	nomore: ''
},
page:1,
size:15
js:
getMessage(){
	uni.showLoading({
		title: "加载中……"
	});
	const mess = {
		name:this.keyword,
		page:this.page,
		size:this.size
	}
	getLegalWorker(mess).then(response => {
		uni.hideLoading();
		if(response.data.code == 200){
			if(response.data.data.length < this.size){  //重要代码
				this.status = "nomore";
			}
			this.cellData.push(...response.data.data)  //重要代码
		} 
	})
}
//上拉刷新事件  //重要代码
onReachBottom() {
	if(this.status == 'nomore'){
		return
	}
	this.page++;
	this.getMessage();
}

以上功能就是一个完整的懒加载分页功能,希望能帮助你!
加油!!!

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐