微信小程序:关于下拉刷新PullDownRefresh

itlao6 原创 开发&源码 微信小程序评论523字数 826阅读2分45秒阅读模式

最近开发一款微信小程序,里面有用到下拉刷新数据的功能。于是,又开始折腾了...

一、onPullDownRefresh回调

初略看了下文档,发现小程序js中有onPullDownRefresh回调,果断重写之...文章源自IT老刘-https://itlao6.com/487.html

  //  http://itlao5.com
  onPullDownRefresh: function () {
    console.log('onPullDownRefresh')
    this.queryData(id)
  },
二、enablePullDownRefresh支持

然而,却发现不管怎么下拉,始终触发不了js回调。
只好继续看文档,发现,需要再json中配置支持下拉刷新,即:文章源自IT老刘-https://itlao6.com/487.html

"enablePullDownRefresh": true  // 请注意是true,不是"true"字符串,
                               // 部分开发者发现设置了还是无效,
                               // 可能是因为设置的"enablePullDownRefresh": "true"

这个可以在app.json中进行全局配置,使所有页面都带有下拉刷新功能;也可以在需要下拉刷新功能的page对应的json中配置。
这下好了,下拉刷新功能完成了。文章源自IT老刘-https://itlao6.com/487.html

三、backgroundTextStyle配置

但是,还有一点点不完美的地方,别人的小程序,下拉刷新时,可以看到顶部有三个点闪烁的动画;而我的小程序顶部一片空白。
原来,还有一个配置,"backgroundTextStyle": "",支持 dark/light;因为我的背景是白色的,此时,不进行这个配置,因为颜色的缘故,三个点闪烁的动画就看不到了,因此,白色背景需要进行以下配置:文章源自IT老刘-https://itlao6.com/487.html

"backgroundTextStyle": "dark"
四、stopPullDownRefresh停止

此外,微信小程序还提供了停止下拉刷新效果的api,如果发现进入刷新状态,无法停止,可以使用这个api文章源自IT老刘-https://itlao6.com/487.html

  // 小程序提供的api,通知页面停止下拉刷新效果
  // http://itlao5.com
  wx.stopPullDownRefresh;
文章源自IT老刘-https://itlao6.com/487.html文章源自IT老刘-https://itlao6.com/487.html
继续阅读
weinxin
我的微信公众号
微信扫一扫关注公众号,不定时更新
itlao6
  • 本文由 发表于 2018年 7月 2日 15:56:58
  • 转载请务必保留本文链接:https://itlao6.com/487.html
评论  0  访客  0
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定