8000 feat(useInfiniteScroll): add a reset method (#3892) · vueuse/vueuse@aefb64f · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit aefb64f

Browse files
authored
feat(useInfiniteScroll): add a reset method (#3892)
1 parent 4a7a8ed commit aefb64f

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

packages/core/useInfiniteScroll/demo.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@ import { ref } from 'vue'
33
import { useInfiniteScroll } from '@vueuse/core'
44
55
const el = ref<HTMLElement | null>(null)
6-
const data = ref([1])
6+
const data = ref<number[]>([])
77
8-
useInfiniteScroll(
8+
const { reset } = useInfiniteScroll(
99
el,
1010
() => {
1111
const length = data.value.length + 1
1212
data.value.push(...Array.from({ length: 5 }, (_, i) => length + i))
1313
},
1414
{ distance: 10 },
1515
)
16+
17+
function resetList() {
18+
data.value = []
19+
reset()
20+
}
1621
</script>
1722

1823
<template>
@@ -21,4 +26,7 @@ useInfiniteScroll(
2126
{{ item }}
2227
</div>
2328
</div>
29+
<button @click="resetList()">
30+
Reset
31+
</button>
2432
</template>

packages/core/useInfiniteScroll/index.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ import { useInfiniteScroll } from '@vueuse/core'
1616
const el = ref<HTMLElement | null>(null)
1717
const data = ref([1, 2, 3, 4, 5, 6])
1818
19-
useInfiniteScroll(
19+
const { reset } = useInfiniteScroll(
2020
el,
2121
() => {
2222
// load more
2323
data.value.push(...moreData)
2424
},
2525
{ distance: 10 }
2626
)
27+
28+
function resetList() {
29+
data.value = []
30+
reset()
31+
}
2732
</script>
2833
2934
<template>
@@ -32,6 +37,9 @@ useInfiniteScroll(
3237
{{ item }}
3338
</div>
3439
</div>
40+
<button @click="resetList()">
41+
Reset
42+
</button>
3543
</template>
3644
```
3745

packages/core/useInfiniteScroll/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,8 @@ export function useInfiniteScroll<T extends InfiniteScrollElement>(
109109

110110
return {
111111
isLoading,
112+
reset() {
113+
nextTick(() => checkAndLoad())
114+
},
112115
}
113116
}

0 commit comments

Comments
 (0)
0