写小程序的时候经常会用到上拉刷新的功能,所以总结了下,以后就可以开开心心的command+c、command+v了!嗨呀、我可真是个聪明的小机灵鬼、哈哈哈
当我们对列表数据进行渲染时所做的分页处理,总结如下
第一步:先在data里面规定页码和每页的条数:
data: {
gw_list:[], // 列表数据
n: 10, // 每页数量
p:1, // 当前页码
},
第二步:触发函数时,给页码➕1,调接口获取数据,最后把数据拼接。
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
var that = this;
var p = that.data.p;
p = p + 1;
var list = that.data.gw_list;
req.post(api.gw_list, {
goods_id: that.data.gid,
n: that.data.n,
p: p,
}, function (ret, data, msg) {
if (ret === "ok") {
console.log(data)
if (data[0]) {
that.setData({
gw_list: list.concat(data),
p: p,
})
} else {
that.setData({
gw_list: list.concat(data),
p: p,
})
wx.showToast({
title: '已显示最多数据',
})
}
} else if (ret === "error") {
//alert(msg);
} else {
//alert(msg);
}
});
},
完成✅