微信小程序下拉刷新和加载更多

在config 的 window中开启 enablePUllDownRefrsh

处理完数据刷新后 wx.stopPullDownRefrsh 可以停止当前页面的刷新

const app = getApp()  
var page = 1;  
var isfinish = false; //加载完毕  
  
function loadmore(that) {  
  if (isfinish) return;  
  
  wx.showLoading({  
    title: '正在加载中',  
  })  
  wx.request({  
    url: app.globalData.url.studentlist,  
    header: {  
      Cookie: wx.getStorageSync('session_id')  
    },  
    data: {  
      page: page,  
      condition: that.data.condition  
  
    },  
      
    success: (res) => {  
      wx.hideLoading();  
  
      if (res.data.length > 0) {  
        var list = that.data.list;  
  
        for (var i = 0; i < res.data.length; i++) {  
          list.push(res.data[i]);  
        }  
        that.setData({ list: list });  
        page++;  
  
      } else {  
        isfinish = true;  
      }  
  
      wx.stopPullDownRefresh();  
    }  
  })  
}

PHP中定义下拉还有加载

//页面相关事件处理函数--监听用户下拉动作  
  onPullDownRefresh: function () {  
    page = 1;  
    isfinish = false;  
    this.setData({list:[]});  
    loadmore(this);  
  },  
 //页面上拉触底事件的处理函数  
   
onReachBottom: function () {  
  var that = this;  
  loadmore(that);  
}, 


你可能感兴趣的:(微信小程序下拉刷新和加载更多)