1.在pages.json 配置文件,为分包goodslist页面配置上拉触底距离
{
"pages": [],
"subPackages": [{
"root": "subpkg",
"pages": [
...
{
"path": "goods_list/goods_list",
"style": {
"navigationBarTitleText": "商品列表",
"enablePullDownRefresh": false,
"onReachBottomDistance": 150
}
}, {
"path": "search/search",
"style": {
"navigationBarTitleText": "搜索",
"enablePullDownRefresh": false
}
}]
}]
...
}
2.goodslist页面中声明onReachBottom事件处理函数监听上拉触底,下拉刷新
onReachBottom() {
if(this.queryObj.pageNum*this.queryObj.pageSize>=this.total)return uni.$showMsg('没有更多数据了');
if (this.isLoading) return;
this.queryObj.pageNum += 1
this.getGoodsList()
},
onPullDownRefresh() {
this.queryObj.pageNum=1;
this.total=0;
this.isLoading=false;
this.goodsList=[];
this.getGoodsList(()=>uni.stopPullDownRefresh())
}
3.当列表数据请求成功之后,进行新旧数据的拼接处理
methods: {
getGoodsList(cb) {
this.isLoading = true;
uni.request({
url: uni.$baseUrl + '/api/Home/GetGoodsList',
}).then((res) => {
this.isLoading = false;
cb && cb();
if (res.data.code != 200) return uni.$showMsg();
this.goodsList = [...this.goodsList,...res.data.data];
this.total = res.data.total;
});
}
}
效果示例