"enablePullDownRefresh": true
onPullDownRefresh() {
//
}
onReachBottom() {
//
}
onShareAppMessage() {
//
}
_load(flag) {
wx.request({
url: this.data.baseUrl + '/good/page?page=' + this.page + '&pageSize=' + this.pageSize,
success: res => {
console.log(res);
this.setData({
goods: [...this.data.goods, ...res.data],
total: res.header['X-Total-Count']
})
//下拉刷新才执行
if(flag){
wx.stopPullDownRefresh()
}
},
fail: err => {
console.log(err);
},
complete: () => {
console.log('log done');
}
})
}
函数声明 - 根据cb的有无决定是否执行特定操作
_load(cb) {
//其他逻辑
cb&cb()
}
函数执行 - 无形参 cb,正常执行
this._load()
函数执行 - 有形参 cb,执行特定操作
this._load(()=>{
wx.stopPullDownRefresh()
})
_load(flag) {
//开始加载时,为真
this.isLoading = true
wx.request({
url: this.data.baseUrl + '/good/page?page=' + this.page + '&pageSize=' + this.pageSize,
success: res => {
console.log(res);
this.setData({
goods: [...this.data.goods, ...res.data],
total: res.header['X-Total-Count']
})
//下拉刷新才执行
if(flag){
wx.stopPullDownRefresh()
}
},
fail: err => {
console.log(err);
},
complete: () => {
console.log('log done');
//加载完毕为假
this.isLoading = false
}
})
}