所用API
https://www.apiopen.top/satinGodApi?type=2&page=1
wxml结构
<view wx:for="{{arr}}" wx:for-index="idx">
<text>序号{{idx}}</text><image src="{{item.header}}"></image>
</view>
js部分
// pages/f/f.js
Page({
data: {
page: 1,//当前页
load:true,
loading:false,
arr:[]
},
onLoad:function(){
var that = this;
var page = that.data.page;
var arr = that.data.arr;
wx.request({
url: 'https://www.apiopen.top/satinGodApi?type=2&page=' + page,
method: 'POST',
success(res){
var arr = res.data.data;
that.setData({
arr: arr
})
}
})
},
onReachBottom: function () {
var that = this;
var arr = that.data.arr;
var page = that.data.page;
// console.log(this);
if(this.data.load){
wx.request({
url: 'https://www.apiopen.top/satinGodApi?type=2&page=' + page,
method: 'POST',
success(res) {
console.log(res)
var listData = arr.concat(res.data.data);
console.log(res.data.data)
that.setData({
arr:listData,
page:page*1+1
})
}
})
}
}
})
网友评论