*.js
const app = getApp();
Page({
data: {
page: 1,
"newslist": {},
},
onLoad: function (options) {
var page = this.data.page;
app.getAjax('api/article', { page: page}, this.callback);
},
callback: function(res){
var that = this;
that.setData({
newslist: res.data
})
},
onReachBottom: function(){
var that =this;
wx.showLoading({
title: '数据加载中',
})
var arr = that.data.newslist;
var page = that.data.page+1;
that.setData({
page: page
})
wx.request({
url: 'http://192.168.1.100/api/article',
header: {
'content-type': 'application/x-www-form-urlencoded',
},
method: 'POST',
data: { page: page},
dataType: 'json',
success: function (res) {
if(res.data.data.length <= 0){
wx.showToast({
title: '数据已全部加载完成',
})
return;
}
for(var i=0; i< res.data.data.length; i++){
arr.push(res.data.data[i]);
}
that.setData({
newslist: arr
})
wx.hideLoading();
}
})
}
})