下拉刷新是常用操作,微信已经集成好了(真机效果稍有瑕疵)
首先需要在.json
文件启用下拉刷新
{"enablePullDownRefresh": true,
}
然后在.js
文件,监听下拉操作,处理loading和请求
onPullDownRefresh() {wx.showNavigationBarLoading();this.setData({page: 1 // 分页重置为第1页});this.getList();
}
最后在接口请求结束,停止下拉刷新,不然不会触发回弹
wx.request({url: 'https://www.xxx.com/api/list',header: {"Content-Type": "application/json"},data: {page: this.data.page},success() {// ...},fail() {// ...},complete() {wx.hideNavigationBarLoading(); wx.stopPullDownRefresh();}
})
欢迎关注:技术开发分享录
