7

How would I make a dynamic dropdown in vue, not sure what I am doing wrong.

in my html I have...

<div id="app">
     <select v-model="selected">
             <option disabled value="">Please select one</option>
             <option v-for="item in selected"></option>
     </select>

and my js looks like....

new Vue({
        el: '#app',
        data: {
          selected: ["Apache", "Cochise"],
        }
      })

filters looks like this enter image description here

EDIT: the values appear in the html DOM tree in the inspector enter image description here

but not in the dropdown enter image description here

1 Answer 1

9

Try this.

new Vue({
    el: '#app',
    data: {
        filters: filters,
        selectedValue: null
    }
})

<div id="app">
     <select v-model="selectedValue">
         <option disabled value="">Please select one</option>
         <option v-for="item in filters" :value="item">{{item}}</option>
     </select>
</div>

Example.

Note: For future readers, there was also an issue where the normal delimiters for text interpolation needed to be customized in @captnvitman's evnironment.

Sign up to request clarification or add additional context in comments.

9 Comments

that work mostly, except for the options do not show in the dropdown, I edited my question with pictures to show what I mean
@captnvitman where does filters come from? And can you link where you are seeing this? It works in the example.
@captnvitman possibly a version issue? I am using Vue 2 in the example.
@captnvitman It looks like you forgot to add {{item}} inside the <option></option>. If you look at your screenshot, there is a value but no text.
for anyone looking at this in the future with the same problem, it was a problem with the delimiters (maybe getting confused with the django templating?) set delimiters: ['${', '}'], in new Vue () and use ${} for vue templating. thanks to @Bert Evans
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.