Using the <select></select> element in Vue can be troublesome. I've found that it tends to give me a bunch of annoyance when used directly on v-models. So instead I usually whip up a custom select component and pass in some props. In this example, I'm just working with static data, but you get the idea.
<template>
<div class="bg-gray-600 w-64" @mouseleave="show = false">
<button @click.prevent="show = !show"
class="w-full px-4 py-2">
{{ selected }}
</button>
<div v-if="show"
class="bg-gray-600 w-64 flex flex-col absolute">
<button v-for="option in options"
:key="option.index"
class="hover:bg-gray-500"
@click.prevent="select(option)">
{{ option }}
</button>
</div>
</div>
</template>
<script>
export default {
name: 'Select',
data(){
return {
show: false,
selected: 'select',
options: [
'select',
'option 01',
'option 02',
'option 03',
'option 04',
'option 05',
]
}
},
methods:{
select(option){
this.selected = option;
this.show = false;
}
}
}
</script>
I'm using Tailwindcss standard classes if you wanted to paste this into a component and start playing with it and keep the basic styles I've applied. If not they're pretty self-descriptive classes.
The reason this works better than <select> is that the v-if removes the "drop-down" div from the dom entirely, then when "show" is true, it re-renders the div with any fresh data you've pushed to the array of options.
This is also a good way to handle a select case if you've using vuex for state management because you can give it more explicit instructions for triggering mutations or actions on the state.
I'm sorry I'm not answering your query directly, but maybe this is another way to approach your issue?
Also, I assume you've solved it yourself since posting this question. so maybe share your own solution?