使用:label-in-value="true" @on-change="obtainValue"iview
詳見官方文檔:https://www.iviewui.com/components/selectui
1 <Select :label-in-value="true" @on-change="obtainValue" v-model="model1" style="width:200px;"> 2 <OptionGroup v-for="(item,key) in selectList" :label="item.groupName" :key="key"> 3 <Option 4 v-for="(item2,key) in item.data" 5 :value="item2.terminalId" 6 :key="key" 7 >{{ item2.terminalName }} 8 </Option> 9 </OptionGroup> 10 </Select>
js:this
model1: "",
stationLabel: "",
obtainValue(e) { this.stationLabel = e.label.replace(/(\s*$)/g, ""); // 獲取顯示在頁面的label值,即{{ item2.terminalName }},而且去掉右空格。
this.model1 = e.value; //獲取綁定的:value="item2.terminalId"值,可當作另外一接口的入參,這個值,在v-model="model1"裏已能獲取,因此可不用再取。
},