//请求数据在上一篇这里只写逻辑
const api =
require(
'../../helper/apis.js')
const req =
require(
"../../helper/req.js")
//index.js
//获取应用实例
const app = getApp()
Page({
data: {
gesslick:[],
page:
2,
isLoading:
false,
isLoadingAll:
false
},
onLoad:
function () {
req.getShops({},{
page:
1,
rows:
10
}).then(res=>{
if(res.length){
this.setData({
guesslick:[...res]
})
}
})
},
onReachBottom(){
let { guesslick, page, isLoading, isLoadingAll} =
this.data;
if (isLoading || isLoadingAll)
return; //防止不必要的请求
this.setData({
isLoading:
true
})
req.getShops({}, {
page: page, //页数
rows:
10 //条数
}).then(res => {
if (res.length) {
this.setData({
guesslick: [...guesslick,...res], //展开后面的数据合并前面数据
page:page+
1,
isLoading:
false
})
}
if(res.error){
this.setData({
isLoading:
false, /
/加载完,显示更多
isLoadingAll:
true /加载完毕 显示没有数据
})
}
})
}
})