创建Data
data: {
articleInfo: [],
flag: true,
index: 1,
},
分页请求数据
onLoad: function (options) {
this.getArticleInfo(this.data.index);
},
getArticleInfo: function(index){
playModel.getAll({
index: index,
success: (res) => {
let newArticleInfo = res.object;
if(newArticleInfo.length == 0){
this.setData({flag: false});
wx.showToast({
title: '已经到底~~',
icon: 'loading',
duration: 2000
})
}else{
let articleInfo = this.data.articleInfo.concat(newArticleInfo);
this.setData({ articleInfo });
}
}
})
},
上拉刷新
onReachBottom: function () {
if(this.data.flag){
let index = this.data.index + 1;
this.setData({index})
this.getArticleInfo(index);
}else{
wx.showToast({
title: '已经到底~~',
icon: 'loading',
duration: 2000
})
}
},
下拉刷新
onPullDownRefresh: function () {
this.setData({
articleInfo: [],
index: 1,
flag: true
})
this.getArticleInfo(this.data.index);
},