Select with dynamic options doesn't keep the correct selected option when shift / unshifting options #230
-
Hi, If a select with v-model has "dynamic" options e.g. I'm guessing the The only workaround I found was re-setting the value after updating the options, is there a more elegant solution? . // Update options.... then
const originalValue = this.selectedItem;
this.selectedItem = null;
this.selectedItem = originalValue; Here's a simplified example, try removing an item ( shift ) and see the select has the wrong selected option |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Thanks for the pointer ( a few extra words would have reduced my googling... 😅) https://vuejs.org/api/built-in-special-attributes.html#key So the key has to be set like this: <select v-model="selectedItem">
<option v-for="item in items" :value="item" :key="item">{{item}}</option>
</select> |
Beta Was this translation helpful? Give feedback.
-
Just a quick side note: ❌ This is wrong: <select v-model="selectedItem">
<template v-for="item in items">
<option :value="item" :key="item">{{item}}</option>
</template>
</select> |
Beta Was this translation helpful? Give feedback.
Thanks for the pointer ( a few extra words would have reduced my googling... 😅)
https://vuejs.org/api/built-in-special-attributes.html#key
So the key has to be set like this: