pages.json
对应的页面下设置style样式,设置上拉触底的距离
"style": {
"onReachBottomDistance": 50 // 上拉触底的单位,单位为px
}
需要上拉触底的vue页面
data() {
return {
// 返回的列表数据
workList: [],
// 携带的参数
query:{
pageNo:1,
pageSize:10
},
// 返回的数据总条数 -->这里返回的total是本次返回的数据总条数,而非所有数据
total:0,
// 数据的状态 loadmore 还有数据需要获取 nomore 不再有更多的数据
dataStatus:'loadmore',
// 页面最下方是否显示 “没有更多了”
notMore: false,
}
},
// 初始化
onShow() {
this.getList();
},
// 监听用户触底刷新事件
onReachBottom(){
if(this.dataStatus=='nomore'){
this.getList();
this.notMore = true;
}
console.log("this.pages",this.query.pageNo);
},
methods: {
getList(){
//判断是否有数据
if(this.dataStatus=='nomore')return;
uni.showLoading({
title:'正在加载...',
mask:true,
})
getWork(this.query).then(res=>{
//合并数据数组
this.workList = this.workList.concat(res.rows);
this.total = res.total;
uni.hideLoading();
//页码数+1
this.query.pageNo++;
res.total==10?this.dataStatus='loadmore':this.dataStatus='nomore';
},err=>{
console.log("失败",err);
uni.hideLoading();
})
},
}