forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptionsDynamic.vue
More file actions
56 lines (47 loc) · 1.12 KB
/
OptionsDynamic.vue
File metadata and controls
56 lines (47 loc) · 1.12 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
<template>
<div class="q-pa-md" style="max-width: 300px">
<q-select
filled
v-model="model"
multiple
:options="options"
:loading="loading"
@virtual-scroll="onScroll"
/>
</div>
</template>
<script>
import { ref, computed, nextTick } from 'vue'
const allOptions = []
for (let i = 0; i <= 100000; i++) {
allOptions.push('Opt ' + i)
}
const pageSize = 50
const lastPage = Math.ceil(allOptions.length / pageSize)
export default {
setup () {
const loading = ref(false)
const nextPage = ref(2)
const options = computed(() => allOptions.slice(0, pageSize * (nextPage.value - 1)))
return {
model: ref(null),
loading,
nextPage,
options,
onScroll ({ to, ref }) {
const lastIndex = options.value.length - 1
if (loading.value !== true && nextPage.value < lastPage && to === lastIndex) {
loading.value = true
setTimeout(() => {
nextPage.value++
nextTick(() => {
ref.refresh()
loading.value = false
})
}, 500)
}
}
}
}
}
</script>