- 上拉刷新
pageView自带上拉刷新方法onReachBottom 实现方法并实现刷新事件
onReachBottom() {
if (!this.data.noMoreData) {
this.loadData(true);
}
}
2.下拉刷新 需要在对应page页面的json文件中配置 然后在该页面的js文件中实现下拉刷新的方法即可
"enablePullDownRefresh": true,
"backgroundTextStyle": "dark"
onPullDownRefresh(){
this.loadData();
}
//结束上拉刷新loading关闭
wx.stopPullDownRefresh();
刷新数据
//加载网络数据
loadData: function (isMore = false) {
var { page } = this.data;
var { limit } = this.data;
if (isMore) {
page++;
} else {
page = 1;
}
this.setData({ page, limit });
let activityRequest = require('../../utils/request');
let urlConst = require('../../utils/api');
activityRequest(urlConst.Action_Activity, {
'page': page,
'limit': limit
}).then((res) => {
if (res.code == 0) {
var resData = res.data;
//取出对应值
var acts = resData.data || [];
var adxs = resData.ads || [];
// 处理tags
acts.forEach((res, index) => {
let list = res.tags.split(',');
res['mytags'] = list;
});
//从data中取出activitys ads
var { activitys } = this.data;
var { ads } = this.data;
if (!isMore) {
//结束上拉刷新loading
wx.stopPullDownRefresh();
activitys = [];
}
var { noMoreData } = this.data;
if (acts.length < this.data.limit) {
console.log('暂无更多数据');
noMoreData = true;
}else{
noMoreData = false;
}
ads = adxs;
activitys = activitys.concat(acts);
this.setData({
ads,
activitys,
noMoreData
});
} else {
if(!isMore){
//结束上拉刷新loading
wx.stopPullDownRefresh();
}
wx.showToast({
title: res.message,
icon: 'none'
})
}
});
},