I have implemented something similar to this code pen in one of my projects.
https://codepen.io/sudheer-ranga/pen/bGVbjbx
There is one issue that am facing, the selected items disappear for invalid search.
So, I found out that the items prop is mutating. Furthermore, I added cache-items prop, that did keep the selected items intact. But now the search would not filter the items.
Next, I added a computed property to get the updated items after search and update it in the items.
computed: {
finalOptions() {
return this.fruitsCopy;
}
}
https://codepen.io/nyfer/pen/VwGdKvy
But that doesn’t work too.
So, I would like to know how I can go about this.
2
Answers
I think the general recommendation is to not implement your own search, but instead use Vuetify’s
v-autocomplete
, which is a select with builtin search capability:If you insist on having the input on top of the item list, you can still use the same slot you used before and make the initial input invisible:
You need to push back selected items to search,
see here codepen.io