下拉刷新
原创
©著作权归作者所有:来自51CTO博客作者wg_iGBFcBFB的原创作品,请联系作者获取转载授权,否则将追究法律责任
"enablePullDownRefresh": true,
"backgroundTextStyle":"dark"
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
console.log('下拉刷新')
//1 重置数组
this.setData({
goods_list:[]
})
// 2 重置页码
this. QueryParmas.pagenum = 1;
// 3 发送请求
this.getGoodsList()
},
// 获取商品列表数据
async getGoodsList(){
const res = await request({
url:'/goods/search',
data:this.QueryParmas
})
// 获取总条数
const total = res.total;
// 计算总页数
this.totalPages = Math.ceil(total / this.QueryParmas.pagesize)
// console.log(this.totalPages)
this.setData({
// 拼接了数组
goods_list: [...this.data.goods_list, ...res.goods]
})
// console.log(res)
// 关闭下拉刷新的窗口
wx.stopPullDownRefresh()
},
// 关闭下拉刷新的窗口
wx.stopPullDownRefresh()