2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-19 09:50:33 +03:00
Files
vue-select/docs/.vuepress/components/InfiniteScroll.vue
T
Jeff Sagal e9ea2d99f3 docs(filtering): Add Filtering Docs (#1017)
docs(infinite-scroll): improve example (#1017)
2020-03-13 09:19:28 -07:00

69 lines
1.4 KiB
Vue

<template>
<v-select
:options="paginated"
:filterable="false"
@open="onOpen"
@close="onClose"
@search="query => search = query"
>
<template #list-footer v-if="hasNextPage">
<li ref="load" class="loader">
Loading more options...
</li>
</template>
</v-select>
</template>
<script>
import countries from '../data/countries';
export default {
name: "InfiniteScroll",
data () {
return {
observer: new IntersectionObserver(this.infiniteScroll),
limit: 10,
search: ''
}
},
computed: {
filtered () {
return countries.filter(country => country.includes(this.search));
},
paginated () {
return this.filtered.slice(0, this.limit);
},
hasNextPage () {
return this.paginated.length < this.filtered.length;
},
},
methods: {
async onOpen () {
if (this.hasNextPage) {
await this.$nextTick();
this.observer.observe(this.$refs.load)
}
},
onClose () {
this.observer.disconnect();
},
async infiniteScroll ([{isIntersecting, target}]) {
if (isIntersecting) {
const ul = target.offsetParent;
const scrollTop = target.offsetParent.scrollTop;
this.limit += 10;
await this.$nextTick();
ul.scrollTop = scrollTop;
}
}
}
}
</script>
<style scoped>
.loader {
text-align: center;
color: #bbbbbb;
}
</style>