2

I've a array and I want put into a <md-select> component. On the offical documentation the list is made from static values.

I'm trying do it:

<md-select v-for="item in group" v-bind:key="item">
    <md-option value="{{item.codigo}}"> {{item.nome}} </md-option>
</md-select>

export default {
  data() {
   return {
      group: []
   }
}

But it not compiles.

1

1 Answer 1

2

You are trying to iterate the <select> tag and that is incorrect, you should iterate the <option> tags, and u need to bind each option value without use {{ }}, just using v-bind or his shortcut : like this:

<md-select v-model="myOptionSelected">
    <md-option 
      v-for="item in group" v-bind:key="item"
      :value="item.codigo"> 
        {{item.nome}} 
    </md-option>
</md-select>

export default {
  data() {
   return {
      myOptionSelected: '',
      group: []
   }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Which difference between v-bind:key and value?
v-bind:key or his shortcut :key is the key for each iteration, value is the value of the current option inside of select. Then when u choose some option his value is taken by the select on his v-model.
i updated my answer, binding value for each option.

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.