微信小程序实现下拉刷新

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

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();
  },
相关推荐
咖啡の猫17 小时前
微信小程序页面事件
微信小程序·小程序·notepad++
咖啡の猫19 小时前
微信小程序网络数据请求
网络·微信小程序·小程序
object not found19 小时前
基于uniapp开发小程序自定义顶部导航栏状态栏标题栏
前端·javascript·小程序·uni-app
咖啡の猫20 小时前
微信小程序案例 - 本地生活(列表页面)
微信小程序·生活·notepad++
咖啡の猫21 小时前
微信小程序案例 - 本地生活(首页)
微信小程序·生活·notepad++
咸虾米_1 天前
uniapp引入iconfont字体图标在微信小程序中适用
微信小程序·小程序·uni-app
咖啡の猫1 天前
微信小程序页面导航
微信小程序·小程序
小咕聊编程1 天前
【含文档+PPT+源码】基于微信小程序的点餐系统的设计与实现
微信小程序·小程序
2501_915918412 天前
如何在iPad上找到并打开文件夹的完整指南
android·ios·小程序·uni-app·iphone·webview·ipad
shejizuopin2 天前
基于Spring Boot+小程序的非遗科普平台设计与实现(毕业论文)
spring boot·后端·小程序·毕业设计·论文·毕业论文·非遗科普平台设计与实现