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
61 lines (52 loc) · 1.09 KB
/
OptionsDynamic.vue
File metadata and controls
61 lines (52 loc) · 1.09 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
<template>
<div class="q-pa-md" style="max-width: 300px">
<div class="q-gutter-md">
<q-select
filled
v-model="model"
multiple
:options="options"
:loading="loading"
@virtual-scroll="onScroll"
/>
</div>
</div>
</template>
<script>
const options = []
for (let i = 0; i <= 100000; i++) {
options.push('Opt ' + i)
}
const pageSize = 50
const nextPage = 2
const lastPage = Math.ceil(options.length / pageSize)
export default {
data () {
return {
model: null,
loading: false,
nextPage
}
},
computed: {
options () {
return Object.freeze(options.slice(0, pageSize * (this.nextPage - 1)))
}
},
methods: {
onScroll ({ to, ref }) {
const lastIndex = this.options.length - 1
if (this.loading !== true && this.nextPage < lastPage && to === lastIndex) {
this.loading = true
setTimeout(() => {
this.nextPage++
this.$nextTick(() => {
ref.refresh()
this.loading = false
})
}, 500)
}
}
}
}
</script>