Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue.js dynamic dropdown

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

like image 825
captnvitman Avatar asked Apr 03 '17 20:04

captnvitman


1 Answers

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.

like image 83
Bert Avatar answered Nov 20 '22 09:11

Bert