To update the select item when the v-model value changes, you can add a watcher to the component that listens for changes to the modelValue prop and updates the select item accordingly. Here's an example:
<script>
import Choices from 'choices.js';
export default {
props: ['options', 'name', 'modelValue'],
emits: ['update:modelValue'],
mounted() {
this.choices = new Choices(this.$refs.select, {
allowHTML: true,
removeItemButton: true
}).setChoices(this.options, 'id', 'name', false).setChoiceByValue(this.modelValue);
},
watch: {
modelValue(newValue) {
this.choices.setChoiceByValue(newValue);
}
}
}
</script>
In this example, we're creating a choices instance in the mounted hook and storing it as a component property. Then, we're adding a watch property to the component that listens for changes to the modelValue prop and updates the choices instance with the new value using the setChoiceByValue method.
Note that we're also using the this.choices property to access the choices instance in the watch handler. This is because the choices instance is not available in the component's scope outside of the mounted hook.