2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-22 10:30:34 +03:00

feat: add open & close events (#1101)

This commit is contained in:
Jeff Sagal
2020-03-12 20:46:08 -07:00
committed by GitHub
parent bb3f28478f
commit e6d0da6d52
4 changed files with 100 additions and 0 deletions
@@ -0,0 +1,72 @@
<template>
<v-select
:options="paginated"
:filterable="false"
@open="onOpen"
@close="onClose"
@search="query => search = query"
ref="select"
>
<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';
import vSelect from '../../../src/components/Select'
export default {
name: "InfiniteScroll",
components: {vSelect},
data: () => ({
observer: null,
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 + 10 < this.filtered.length;
},
},
mounted () {
this.observer = new IntersectionObserver(this.infiniteScroll);
},
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>
+1
View File
@@ -120,6 +120,7 @@ module.exports = {
['guide/validation', 'Validation'],
['guide/selectable', 'Limiting Selections'],
['guide/pagination', 'Pagination'],
['guide/infinite-scroll', 'Infinite Scroll'],
['guide/vuex', 'Vuex'],
['guide/ajax', 'AJAX'],
['guide/loops', 'Using in Loops'],