Trying out this event filtering example
This can be successful
Index.vue
<template>
<q-select
:options="options"
@filter="filter"
v-model="model"
use-input
></q-select>
</template>
<script>
import { defineComponent } from "vue";
import { computed, reactive, toRefs, ref } from "vue";
const selectedOptions = ["Google", "Facebook", "Twitter", "Apple", "Oracle"];
export default defineComponent({
name: "PageIndex",
setup() {
let state = reactive({
model: null,
options: selectedOptions,
});
const filter = (val, update, abort) => {
update(() => {
const needle = val.toLowerCase()
state.options = selectedOptions.filter(v => v.toLowerCase().indexOf(needle) > -1)
})
}
return {
filter,
selectedOptions,
...toRefs(state),
};
},
});
</script>
Attempting to implement a common function from utils/filter.js without success
Index.vue
<template>
<q-select
use-input
:options="options"
@filter="
(val, update, abort) =>
filter(val, update, abort, selectedOptions, options)
"
v-model="model"
> </q-select>
</template>
<script>
import { defineComponent } from "vue";
import { computed, reactive, toRefs, ref } from "vue";
import { filter } from "../utils/filter";
const selectedOptions = ["Google", "Facebook", "Twitter", "Apple", "Oracle1"];
export default defineComponent({
name: "PageIndex",
setup() {
let state = reactive({
model: null,
options: selectedOptions,
});
return {
filter,
selectedOptions,
...toRefs(state),
};
},
});
</script>
utils/filter.js
export function filter(val, update, abort, from, to) {
update(() => {
const needle = val.toLowerCase()
to.value = from.filter((v) => v.toLowerCase().indexOf(needle) > -1)
})
}
How can we make the filtering work effectively?
Working version https://codesandbox.io/s/blissful-brattain-vd085n?file=/src/pages/Index.vue
Not working version https://codesandbox.io/s/blissful-brattain-vd085nv2-forked-feiv7v?file=/src/pages/Index.vue