微信小程序列表无限上拉加载

  <view class="List" wx:for="{{List}}">
    {{item}}
  </view>

  

data: { List:[],//定义成空数组 currentPage:1, //默认第一页 },
 
  onLoad: function (options) {
        this.List()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
   // 滚动到页面执行该方法 
   let that = this
   //默认page是第一页 上啦滚动到页面底部页面+1
   let currentPage =that.data.currentPage+1
   that.setData({
     currentPage:currentPage
   })
     that.List()
  },

  List: function () {
        let that = this
        let data = {
              page:that.data.currentPage,
              row: 6,
               }
              app.globalData.get(app.globalData.Api.List, data)
                .then(res => {
                  console.log(res)
                    //用concat把数据连接起来
                    this.setData({
                      List:this.data.List.concat(res.ResData.Items)
                    })
        
                })
                .catch(err => {
                  console.log(err)
                })
            },

  

posted @ 2021-03-09 14:38  .晴天  阅读(106)  评论(0)    收藏  举报