微信小程序实现下拉刷新

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

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();
  },
相关推荐
The_era_achievs_hero40 分钟前
微信小程序41~50
微信小程序·小程序
走,带你去玩9 小时前
uniapp 微信小程序水印
微信小程序·小程序·uni-app
是一碗螺丝粉9 小时前
🔥 微信H5视频自动播放终极秘籍:WeixinJSBridge竟是官方“通行证”?
微信小程序
一笑code10 小时前
vue/微信小程序/h5 实现react的boundary
微信小程序·vue·react
菌菇汤11 小时前
uni-app实现单选,多选也能搜索,勾选,选择,回显
前端·javascript·vue.js·微信小程序·uni-app·app
CC同学呀18 小时前
从0到100:单位订餐统计小程序开发日记2025
小程序
666HZ6661 天前
微信小程序中scss、ts、wxml
微信小程序·小程序·scss
二十十十十十1 天前
微信点餐小程序—美食物
微信·小程序
向明天乄1 天前
在小程序中实现实时聊天:WebSocket最佳实践
websocket·网络协议·小程序
h185385922441 天前
租车小程序电动车租赁小程序php方案
小程序