2017-09-29 29 views
0

V模型和select語句我有以下vuejs代碼:弄不清vuejs2

 <select v-model='selectedInverter' class="custom-select" @change="changedInverter"> 
      <option>Select an inverter</option> 
      <template v-for="inverter in localInverters"> 
      <option>{{inverter.display_name}}</option> 
      </template> 
     </select> 

如果我在changedInverterconsole.log(this.selectedInverter),我得到的只是DISPLAY_NAME而不是整個對象。如何捕獲(或綁定)V模型中的整個對象?

回答

1

關於這個文件是在這裏:https://vuejs.org/v2/guide/forms.html#Select

如果向下滾動到動態部分的選項,你會看到示例代碼,將讓你在你需要爲:

<select v-model="selected"> 
    <option v-for="option in options" v-bind:value="option.value"> 
    {{ option.text }} 
    </option> 
</select> 
<span>Selected: {{ selected }}</span> 

在你情況下,您的v-bind:value數據將是整個inverter對象,其中選項文本將爲{{inverter.display_name}},因爲您已經擁有了該對象。