Vue Selected Bind Does Not Work on Option Tags
See original GitHub issueVersion
2.5.16
Reproduction link
https://codepen.io/jbenner/pen/geJqex
Steps to reproduce
- Instantiate a Vue instance with a
data
property namedlocations
which is an array consisting of['all', 'north', 'south', 'east', 'west']
. - Iterate over the locations in an
option
tag like so<option v-for="location in locations" :selected="location === 'all'">{{ location }}</option>
.
What is expected?
The selected
attribute to be set on the “all” option
element.
What is actually happening?
The selected
attribute is not being set.
I’ve also tried the following while attempting to debug but to no avail:
<option v-for="(location, index) in locations" :selected="index === 0">{{ location }}</option>
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:6 (2 by maintainers)
Top Results From Across the Web
vue.js - Vuejs v-on:click not working on option tag
Instead of binding your selected option to a property of the display object, just bind it to the display object itself.
Read more >Form Input Bindings - Vue.js
You can use the v-model directive to create two-way data bindings on form input, textarea, and select elements. It automatically picks the correct...
Read more >How to Use the Select Tag with Vue - Mastering JS
Here's how you can use Vue with the `select` tag, including how to use two way data binding with `v-model`.
Read more >Vue.js Form Input Binding with Select option - GeeksforGeeks
Form Input Binding with Select option is used to handle the value binding for the select element. The select element uses the value...
Read more >Bind select to vue - Material Design for Bootstrap
selected ); } } }); If i do not use mdb-select this code works, how can i get it to work with your...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
One workaround is to create a directive (named
"attr"
) that sets the attribute:Then use it in your template like
v-bind
but withv-attr
:updated codepen
https://stackoverflow.com/a/67577063/6277151
I’m running into a similar issue on a select box where I can’t use v-model. Is there a workaround or fix for this issue?