微信小程序 下拉刷新,上拉分页

手机APP/开发
371
0
0
2022-09-13

上拉分页(onReachBottom函数)

参数:

  • wx.showLoading() 表示上拉刷新数据的样式
  • title: ‘加载中’, //表示加载时友好提示的文字
  • mask: true
  • wx.showToast() 表示数据加载完毕友好提示的文字
  • title: ‘最后一页啦!’,
  • icon: ‘success’,
  • duration: 2000

完整代码实例

onReachBottom(){
//点击之后直接给加载界面
  wx.showLoading({
  title: '加载中',
  mask: true
})

var aa  = this.data.jj.length;
//获取当前的行数为一行
var length = aa+5;
// 每次刷新加载五行
var that = this;
wx.request({
  url: "http://www.10.com/index.php/api/api?length="+length,//请求地址
  method:'GET',
  dataType:'json',
 success(res)
 {
  that.setData({
    jj:res.data.data.data//这个border跟上面data里面的border是对应的。
  })
    if( length > res.data.data.data.length ){
      wx.showToast({
        title: '最后一页啦!',
        icon: 'success',
        duration: 2000
      })
    }

    wx.hideLoading({})
   console.log(res.data.data.data.length)
 },
 error:function(err)
 {
   console('服务器请求失败');
 }
})
},