pull-refresh.vue
943 Bytes
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
40
41
42
43
44
45
46
47
48
49
50
51
52
<template>
<scroll-view
class="scroll-view"
:scroll-y="scrollY"
refresher-threshold="50"
refresher-enabled
:refresher-triggered="value"
@scrolltolower="onLower"
@refresherpulling="onPulling"
@refresherrefresh="onRefresh"
@refresherrestore="onRefreshed"
@refresherabort="onRefreshed"
>
<slot></slot>
</scroll-view>
</template>
<script>
export default {
props: {
value: Boolean,
scrollY: {
type: Boolean,
default: true
}
},
methods: {
onPulling(e) {
if (e.detail.deltaY < 0) return // 防止上滑页面也触发下拉
this.$emit('input', true)
},
onRefresh() {
this.$emit('refresh')
},
onRefreshed() {
this.$emit('input', false)
},
onLower() {
this.$emit('lower', false)
}
}
}
</script>
<style>
.scroll-view {
display: block;
width: 100%;
height: 100%;
box-sizing: border-box;
}
</style>