微信小程序-上拉加载和下拉刷新

一.上拉加载

微信小程序的上拉加载使用onReachBottom(),写在.js文件里面的Page方法里面。

复制代码
onReachBottom(){
    //上拉自动更新到4,5,6
    wx.showLoading({
      title: '数据加载中...',
    })
    setTimeout(()=>{
      const lastNum=this.data.numList[this.data.numList.length-1]
      const newAry=[lastNum+1,lastNum+2,lastNum+3]
      this.setData({
        numList:[...this.data.numList,...newAry]
      })
      wx.hideLoading()
    },1500)
  }

onReachBottom()会监听微信小程序上拉操作。

需要在.json文件里面配置"onReachBottomDistance"属性。

如下面的代码,在距离底部50px的时候会触发到onReachBottom()

复制代码
"onReachBottomDistance": 50px

二.下拉刷新

下拉刷新使用onPullDownRefresh()

复制代码
  onPullDownRefresh(){
    //下拉刷新后,显示1,2,3
    this.setData({
      numList:[1,2,3]
    })
    if(this.data.numList.length === 3){
      wx.stopPullDownRefresh()
    }
  }

注意,在使用onPullDownRefresh() 的时候,需要及时使用wx.stopPullDownRefresh()进行关闭,不然可能会长时间显示刷新状态

相关推荐
double_eggm4 小时前
微信小程序8
微信小程序·小程序
MageGojo4 小时前
小程序每日一谜怎么做:riddle 接口接入示例
windows·小程序·apache·谜语
kyh100338112015 小时前
Cocos Creator 《打螺丝消除游戏》源码+实现
游戏·微信小程序·小程序·打螺丝小游戏源码·微笑小游戏源码
烂不烂问厨房1 天前
支付宝小程序camera录制视频并上传注意事项
小程序·音视频
PeanutSplsh1 天前
wx.setStorage 存的数据,没你以为的那么安全
微信小程序
我是伪码农1 天前
小程序125-150
小程序
帅次1 天前
讯飞与腾讯云:Android 实时语音识别服务对比选择
android·ios·微信小程序·小程序·android studio·android runtime
Chengbei111 天前
小程序 AI 渗透新工具MCP!打通调试与安全检测、网络抓包、接口分析、越权检测一站式实现
人工智能·安全·web安全·搜索引擎·网络安全·小程序·系统安全
2501_915909061 天前
深入理解HTTPS中间人抓包技术原理与实战指南
网络协议·http·ios·小程序·https·uni-app·iphone
he___H1 天前
微信小程序实现两行交错功能
微信小程序·小程序