当前位置:   article > 正文

微信小程序实现下拉刷新_微信小程序 下拉刷新

微信小程序 下拉刷新

一、设置微信小程序所有页面都可以下拉刷新
1、在app.json的"window"中进行配置

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

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

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

  1. onPullDownRefresh:function(){
  2. this.onRefresh();
  3. },
  4. onRefresh:function(){
  5. //导航条加载动画
  6. wx.showNavigationBarLoading();
  7. setTimeout(function () {
  8. wx.hideNavigationBarLoading();
  9. //停止下拉刷新
  10. wx.stopPullDownRefresh();
  11. }, 2000);
  12. },

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

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

“enablePullDownRefresh”: true

  1. {
  2. "usingComponents": {},
  3. "enablePullDownRefresh": true
  4. }

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

  1. onRefresh:function(){
  2. //导航条加载动画
  3. wx.showNavigationBarLoading()
  4. //loading 提示框
  5. wx.showLoading({
  6. title: 'Loading...',
  7. })
  8. console.log("下拉刷新啦");
  9. setTimeout(function () {
  10. wx.hideLoading();
  11. wx.hideNavigationBarLoading();
  12. //停止下拉刷新
  13. wx.stopPullDownRefresh();
  14. }, 2000)
  15. },

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

  1. /**
  2. * 页面相关事件处理函数--监听用户下拉动作
  3. */
  4. onPullDownRefresh:function(){
  5. this.onRefresh();
  6. },

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/221199
推荐阅读
相关标签
  

闽ICP备14008679号