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

一.上拉加载

微信小程序的上拉加载使用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()进行关闭,不然可能会长时间显示刷新状态

相关推荐
00后程序员张1 天前
python 抓包在实际项目中的合理位置,结合代理抓包、设备侧抓包与数据流分析
android·ios·小程序·https·uni-app·iphone·webview
2501_915918411 天前
使用 HBuilder 上架 iOS 应用时常见的问题与应对方式
android·ios·小程序·https·uni-app·iphone·webview
2501_916007471 天前
iOS 崩溃日志的分析方法,将崩溃日志与运行过程结合分析
android·ios·小程序·https·uni-app·iphone·webview
2501_916007471 天前
React Native 混淆在真项目中的方式,当 JS 和原生同时暴露
javascript·react native·react.js·ios·小程序·uni-app·iphone
00后程序员张1 天前
苹果应用商店上架App流程,签名证书、IPA 校验、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_916007471 天前
iOS 上架需要哪些准备,围绕证书、描述文件和上传方式等关键环节展开分析
android·ios·小程序·https·uni-app·iphone·webview
qq_12498707531 天前
基于微信小程序的私房菜定制上门服务系统(源码+论文+部署+安装)
java·spring boot·微信小程序·小程序·毕业设计·毕设
2501_915106321 天前
iOS 上架费用解析,哪些成本可以通过流程优化降低。
android·ios·小程序·https·uni-app·iphone·webview
换日线°1 天前
微信小程序找不同游戏(有效果图)
游戏·微信小程序
风月歌1 天前
小程序项目之超市售货管理平台小程序源代码(源码+文档)
java·微信小程序·小程序·毕业设计·源码