1、设置页面刷新和滚动属性
backgroundTextStyle:设置下拉背景字体、loading 图的样式,设置为黑色
enablePullDownRefresh:设置是否开启下拉刷新,设置为true
disableScroll:设置为页面整体是否不可以上下滚动,设置为false
{
"backgroundTextStyle": "dark",
"enablePullDownRefresh": true,
"disableScroll": false
}
2、修改下拉动作处理函数onPullDownRefresh和上拉触底事件处理函数onReachBottom
const app = getApp()
var array = []
Page({
data: {
catid: 430,
imgList: []
},
/**
* 请求图片
*/
loadImgList: function (that) {
var currCatid = that.data.catid
//console.log("当前页数:", currCatid)
wx.request({
url: 'https://xxx?catid=' + currCatid,
data: {},
header: { 'content-type': 'application/json;charset=utf-8' },
success: function (res) {
if (res != null && res != undefined && res.data.ret == 'succ') {
for (var index in res.data.sucais) {
array.push(res.data.sucais[index])
}
that.setData({
catid: currCatid + 1,
imgList: array
})
}
//console.log("图片获取返回结果:", that.data.imgList)
}
})
},
onLoad: function () {
this.loadImgList(this)
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
console.log('顶部下拉刷新')
this.data.catid = 1
array = []
this.loadImgList(this)
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
console.log('底部上拉追加新的一页')
this.loadImgList(this)
},
})