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

一.上拉加载

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

相关推荐
我是伪码农1 小时前
小程序100-125
开发语言·小程序·php
咖啡八杯1 天前
微信小程序人脸认证1.0迁移2.0
后端·微信小程序
xshirleyl1 天前
微信小程序开发week8-慕尚花坊项目
微信小程序·小程序
admin and root1 天前
Claude+Trae大模型 配置Chrome MCP联动Yakit自动化渗透测试
微信小程序·渗透测试·自动化·攻防演练·ai安全·claude code·ai自动化渗透测试
code_li2 天前
小程序上线需要的资质证书汇总
小程序·上线·发布·资质
hnxaoli2 天前
统信小程序(十三)循环键鼠操作程序
python·小程序
i查拉图斯特拉如是2 天前
使用workbuddy 30分钟搭建微信小程序
微信小程序·小程序
IceSugarJJ2 天前
Open-AutoGLM项目学习
语言模型·微信小程序·github
2501_916008892 天前
Mac 上生成 AppStoreInfo.plist 文件,App Store 上架
android·macos·ios·小程序·uni-app·iphone·webview
咖啡の猫2 天前
小程序协同工作和发布
小程序