微信小程序的上拉加载,下拉刷新

微信小程序的上拉加载和下拉刷新有点不一样

我们先在所需要进行上拉加载和下拉刷新的页面进行开启这项操作的步骤一

“enablePullDownRefresh":true

当我们进行开启后,我们先进行下拉刷新

 

const app=getApp()​
Page({
    /**
     * 页面的初始数据
     */
    data: {
        llll:{},
    },
 onLoad: function (e) {
        this.data.llll=e  
    },

​
/**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        let ii=this.data.llll
        console.log(ii);

        //再次渲染页面

        app.http.search(ii).then(res=>{
          console.log(res);
          this.setData({
              search:res.data.message.goods
          })
      })
  
    },
})

我们将所需要刷新的数据放在 onPullDownRefresh 中便可进行下拉刷新

上拉加载也是如此,我们上拉加载也是有专用的上拉加载生命周期函数

const app=getApp()
 Page({

    /**
     * 页面的初始数据
     */
    data: {
        total:0
    },
can{
      pagesize:8,
      pagenum:1
    },

totalll:1,

    onLoad: function (e) {
        console.log(e);
        this.can.cid=e.cid_id||''
        this.can.query=''

        this.data.llll=e

        app.http.search({
          cid:e.cid_id
        }).then(res=>{
          this.setData({
            total:res.data.message.total
          })

          //将数据进行分割

          this.totalll=Math.ceil(this.data.total/this.can.pagesize)
          console.log(this.totalll);
      })
    },

 onReachBottom: function () {
      var that=this
      console.log(1);

      //展示的数据的多少进行判断

      if(that.can.pagenum<that.totalll){
        that.can.pagenum++
        console.log(that.can.pagenum);
        app.http.search(that.can).then(res=>{
          console.log(res);
          that.setData({
              search:[...that.data.search,...res.data.message.goods]
          })
      })
      }else{
        wx.showToast({
          title: '没有下一页数据',
        })
      }
      
    },
})

这样就完成了上拉加载,另外请求方式是我们自己promise封装的wx.request

如何promise封装的wx.request和使用,在第一篇博客中

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值