官方文档: 点击前往
1 2 3 4 5 6 7 8 9
| <scroll-view scroll-y :refresher-threshold="45" :refresher-enabled="true" :refresher-triggered="refresherTriggered" @refresherrefresh="refresherrefresh" @refresherrestore="refresherrestore" @refresherabort="refresherabort" <view>内容内容内容内容内容内容内容内容内容</view> </scroll-view>
|
1 2 3 4 5 6
| data() { return { refresherTriggered: false, _refresherTriggered: false } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| methods: { refresherrefresh(){ console.log("自定义下拉刷新被触发"); let _this = this; if (_this._refresherTriggered) { return; } _this._refresherTriggered = true; if (!_this.refresherTriggered) { _this.refresherTriggered = true; } this.loadStoreData(); }, refresherrestore(){ console.log("自定义下拉刷新被复位"); let _this = this; _this.refresherTriggered = false; _this._refresherTriggered = false; }, refresherabort(){ console.log("自定义下拉刷新被中止 "); let _this = this; _this.refresherTriggered = false; _this._refresherTriggered = false; }, loadStoreData() { let _this = this; this.listData(); setTimeout(() => { _this.refresherTriggered = false; _this._refresherTriggered = false; }, 1000) }, listData() { let _this = this; }, }
|
注意:_refresherTriggered 的作用是用于缓存状态,防止loadStoreData这个异步操作没有完成的时候再次刷新
uniapp开发中 scroll-view 自定义下拉刷新实现