技术笔记
小程序分页加载onReachBottom上划触底操作
 moons   2020-07-27 17:18:52   130
专栏分类: javascript
    data: {
        limit: 11,//显示数据量
        list: '',
        page: 1,//当前页
        load: true,
        loading: false,//加载动画的显示
      },
    onReachBottom: function () {
        var that = this;
        if (that.data.load) {//全局标志位,方式请求未响应是多次触发
          if (that.data.list.length < that.data.count) {
              that.setData({
                load: false,
                loading: true,//加载动画的显示
              })
              wx.request({
                url: 'url',
                data: {
                },
                method: 'POST',
                success: function (res) {
                  console.log(res)
                  var content = that.data.list.concat(res.data.data.list)//将放回结果放入content
                  that.setData({
                    list: content,
                    page: that.data.page * 1 + 1,
                    load: true,
                    loading: false,
                   })
                },
                fail: function (res) {
                    that.setData({
                      loading: false,
                      load: true,
                    })
                    wx.showToast({
                      title: '数据异常',
                      icon: 'none',
                      duration: 2000,
                    }) 
                   },
                complete: function (res) { },
              })
          }
        }
      },
Copyright © mos360.cn By Moons Soft Studio 百度统计