forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrollTo.vue
More file actions
86 lines (76 loc) · 1.72 KB
/
ScrollTo.vue
File metadata and controls
86 lines (76 loc) · 1.72 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<template>
<div>
<div class="q-pa-md row justify-center">
<q-input
style="min-width: 10em"
type="number"
v-model.number="virtualListIndex"
:min="0"
:max="9999"
label="Scroll to index"
input-class="text-right"
outlined
/>
<q-btn
class="q-ml-sm"
label="Go"
no-caps
color="primary"
@click="executeScroll"
/>
</div>
<q-separator />
<q-virtual-scroll
ref="virtualListRef"
style="max-height: 300px;"
component="q-list"
:items="heavyList"
separator
@virtual-scroll="onVirtualScroll"
>
<template v-slot="{ item, index }">
<q-item
:key="index"
dense
:class="{ 'bg-black text-white': index === virtualListIndex }"
>
<q-item-section>
<q-item-label>
#{{ index }} - {{ item.label }}
</q-item-label>
</q-item-section>
</q-item>
</template>
</q-virtual-scroll>
</div>
</template>
<script>
import { ref, onMounted } from 'vue'
const maxSize = 10000
const heavyList = []
for (let i = 0; i < maxSize; i++) {
heavyList.push({
label: 'Option ' + (i + 1)
})
}
export default {
setup () {
const virtualListRef = ref(null)
const virtualListIndex = ref(1200)
onMounted(() => {
virtualListRef.value.scrollTo(virtualListIndex.value)
})
return {
heavyList,
virtualListRef,
virtualListIndex,
onVirtualScroll ({ index }) {
virtualListIndex.value = index
},
executeScroll () {
virtualListRef.value.scrollTo(virtualListIndex.value, 'start-force')
}
}
}
}
</script>