uni-app在ios中下拉刷新多次触发解决方法

  • 在使用uni-app的时候, 忽然发现ios在使用onPullDownRefresh方法下拉刷新的时候 可以看到后台会一连访问几十次
// 页面下拉
		onPullDownRefresh() {
		    uni.startPullDownRefresh({}) // 开启刷新, 但是在这里不能再用了,因为onPullDownRefresh已经自动开启刷新了
			this.getCommend(this.mobile)
			let url = '/product/mobile/list'
			if (this.mobile != '') {
				url += '?mobile=' + this.mobile
			}
			this.apireq.req({
				url: url,
				mothod: 'GET',
				success: (res) => {
					// console.log(res)
					this.current = 0
					this.classInfoList = []
					this.setData = []
					this.classInfoList = res.data
					this.setData = res.data.slice(this.current, this.current + 2)
					this.current = this.current + 2
					// console.log(this.current, this.setData)
					uni.stopPullDownRefresh()
				}
			})
		},
  • 经过查看文档发现, 原来是 onPullDownRefresh方法 使用后, 只要下拉就已经触发事件, 不能再使用uni.startPullDownRefresh()
  • 只需要在数据请求完成后使用 uni.stopPullDownRefresh 停止刷新就可以了

猜你喜欢

转载自blog.csdn.net/weixin_45289067/article/details/97264996
今日推荐