微信小程序实现下拉刷新

一、设置微信小程序所有页面都可以下拉刷新

1、在app.json的"window"中进行配置

(1)把"backgroundTextStyle":"light"改为"backgroundTextStyle":"dark"

(2)添加"enablePullDownRefresh":true,开启下拉刷新。

1.在app.js中增加两个生命周期函数

javascript 复制代码
onPullDownRefresh:function(){
    this.onRefresh();
  },
onRefresh:function(){
    //导航条加载动画
    wx.showNavigationBarLoading();
    setTimeout(function () {
      wx.hideNavigationBarLoading();
      //停止下拉刷新
      wx.stopPullDownRefresh();
    }, 2000);
  },

二、设置微信小程序单独页面下拉刷新

1、首先在页面的json文件中添加设置:

"enablePullDownRefresh": true

javascript 复制代码
{             
  "usingComponents": {},
  "enablePullDownRefresh": true
}

2、在js文件中写一个onRefresh()生命周期:

javascript 复制代码
onRefresh:function(){
    //导航条加载动画
    wx.showNavigationBarLoading()
    //loading 提示框
    wx.showLoading({
      title: 'Loading...',
    })
    console.log("下拉刷新啦");
    setTimeout(function () {
      wx.hideLoading();
      wx.hideNavigationBarLoading();
      //停止下拉刷新
      wx.stopPullDownRefresh();
    }, 2000)
  },

3、在onPullDownRefresh()中调用上面写的函数:

javascript 复制代码
/**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh:function(){
    this.onRefresh();
  },
相关推荐
码起来呗12 分钟前
基于Spring Boot的乡村拼车小程序的设计与实现-项目分享
spring boot·后端·小程序
2501_916007471 小时前
iOS文件管理工具深度剖析,从系统沙盒到跨平台文件操作的多工具协同实践
android·macos·ios·小程序·uni-app·cocoa·iphone
wapchief2 小时前
微信小程序camera相机帧转图片base64
微信小程序·小程序
QuantumLeap丶2 小时前
《uni-app跨平台开发完全指南》- 05 - 基础组件使用
vue.js·微信小程序·uni-app
发财北2 小时前
全屋智能家居定制小程序
小程序
2501_915918413 小时前
Flutter 加固方案对比与实战,多工具组合的跨平台安全体系(Flutter App 加固/IPA 成品混淆/Ipa Guard CLI/自动化安全流程)
安全·flutter·ios·小程序·uni-app·自动化·iphone
泽_浪里白条4 小时前
UniApp + Vue3 开发微信小程序数字人:TTS PCM 音频流与 SVGA 动画同步实战
微信小程序
小蒜学长4 小时前
springboot基于Java的校园导航微信小程序的设计与实现(代码+数据库+LW)
java·spring boot·后端·微信小程序
说私域4 小时前
定制开发AI智能名片S2B2C商城小程序的发展与整合资源策略研究
人工智能·小程序
WenGyyyL5 小时前
微信小程序开发——第二章:微信小程序开发环境搭建
开发语言·python·微信小程序