2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-16 09:10:33 +03:00

docs(filtering): Add Filtering Docs (#1017)

docs(infinite-scroll): improve example (#1017)
This commit is contained in:
Jeff Sagal
2020-03-13 09:19:28 -07:00
committed by GitHub
parent 85519c039e
commit e9ea2d99f3
7 changed files with 64 additions and 21 deletions
@@ -1,9 +1,10 @@
<template>
<div>
<v-select
placeholder="choose a country"
v-model="selected"
:options="['Canada', 'United States']"
:components="{Deselect}"
:options="['Canada', 'United States']"
/>
</div>
</template>
+31
View File
@@ -0,0 +1,31 @@
<template>
<v-select :filter="fuseSearch" :options="books" :getOptionLabel="option => option.title">
<template #option="{author, title}">
{{ title }} <br>
<cite>{{ author.firstName }} {{ author.lastName }}</cite>
</template>
</v-select>
</template>
<script>
import Fuse from 'fuse.js';
import books from '../data/books';
export default {
computed: {
books: () => books,
},
methods: {
fuseSearch (options, search) {
const fuse = new Fuse(options, {
keys: ['title', 'author.firstName', 'author.lastName'],
shouldSort: true,
});
return search.length ? fuse.search(search) : fuse.list;
},
},
};
</script>
<style scoped>
</style>
+8 -12
View File
@@ -5,7 +5,6 @@
@open="onOpen"
@close="onClose"
@search="query => search = query"
ref="select"
>
<template #list-footer v-if="hasNextPage">
<li ref="load" class="loader">
@@ -17,16 +16,16 @@
<script>
import countries from '../data/countries';
import vSelect from '../../../src/components/Select'
export default {
name: "InfiniteScroll",
components: {vSelect},
data: () => ({
observer: null,
limit: 10,
search: ''
}),
data () {
return {
observer: new IntersectionObserver(this.infiniteScroll),
limit: 10,
search: ''
}
},
computed: {
filtered () {
return countries.filter(country => country.includes(this.search));
@@ -35,12 +34,9 @@ export default {
return this.filtered.slice(0, this.limit);
},
hasNextPage () {
return this.paginated.length + 10 < this.filtered.length;
return this.paginated.length < this.filtered.length;
},
},
mounted () {
this.observer = new IntersectionObserver(this.infiniteScroll);
},
methods: {
async onOpen () {
if (this.hasNextPage) {
-5
View File
@@ -226,11 +226,6 @@ export default {
loading(false);
});
}, 250),
fuseSearch (options, search) {
return new Fuse(options, {
keys: ['title', 'author.firstName', 'author.lastName'],
}).search(search);
},
},
};
</script>
+2 -1
View File
@@ -131,7 +131,8 @@ module.exports = {
collapsable: false,
children: [
['guide/keydown', 'Keydown Events'],
['guide/positioning', 'Dropdown Position']
['guide/positioning', 'Dropdown Position'],
['guide/filtering', 'Option Filtering'],
],
},
{