下拉刷新_下拉刷新

 

 

 

下拉刷新_下拉刷新_02

 

 

 "enablePullDownRefresh": true,
  "backgroundTextStyle":"dark"
 
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
      console.log('下拉刷新')
      //1 重置数组
      this.setData({
        goods_list:[]
      }) 
      // 2 重置页码
      this. QueryParmas.pagenum = 1;
      // 3 发送请求
      this.getGoodsList()
  },
 
 

下拉刷新_下拉刷新_03

 

 // 获取商品列表数据
   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()