1.下拉刷新,需要在window开启全局配置
"enablePullDownRefresh": true
2.在data里设置当前页为1
data: {
page: 1
},
2页面刷新展示
onPullDownRefresh: function () {
let that = this;
let page = this.data.page; //获取当前的页数
wx.request({
url: 'http://www.day.com/index.php/admin/activity', //仅为示例,并非真实的接口地址
header: {
'content-type': 'application/json'
},
data: {
page: page + 1
},
success(res) {
let activityData = res.data.data.data;
that.setData({
activity: activityData,
page: page,
})
if (activityData.length > 0) {
wx.showToast({
title: '刷新成功',
icon: 'success'
})
}
}
})
},
3.上拉展示
onReachBottom: function () {
console.log("上拉了");
let that = this;
let page = this.data.page;
wx.request({
url: 'http://www.day.com/index.php/admin/activity', //仅为示例,并非真实的接口地址
header: {
'content-type': 'application/json' // 默认值
},
data: {
page: page + 1,
},
success(res) {
console.log(res.data.data);
let value = res.data.data.data;
that.setData({
activity: that.data.activity.concat(value),
page: page + 1,
})
if (value.length > 0) {
wx.showToast({
title: '正在加载数据中...',
icon: 'loading'
})
} else {
wx.showToast({
title: '暂无最新的数据了...',
icon: 'none'
})
}
}
})
},
|