[Vuejs]-Vuejs How to assign value to select options

0👍

just use chosenFields[] as v-model of select with index i of v-for. you will get selected values in chosenFields array

<tr v-for="(header,i) in fileHeaders" :key="header">
   <td>{{header}}</td>
   <td>
     <select class="form-control" v-model="chosenFields[i]" v-on:change="setField">
        <option selected>Choose option</option>
        <option value="company_name">Company name</option>
        <option value="address">Address</option>
        <option value="zipcode">Zipcode</option>
        <option value="city">City</option>
        <option value="email">Email</option>
        <option value="number">Phonenumber</option>
        <option value="contact_person">Contact person</option>
        <option value="cvr_number">ID</option>
    </select>
  </td>
</tr>
    
    data() {
      return {
        fileHeaders: ['Company Name', 'Zipcode', 'City' etc.],
        selectedField: "",
        chosenFields: []
      };
    }

Leave a comment