vue中一般select都綁定v-model,但是v-model只保存value值,如果想同時取出option的文本,則麻煩些
下面方法目前只適用於select單選
方法:
1.給select 加 ref屬性
<Select placeholder="請選擇" v-model="currentTemplate" ref="newText" @change="insertTemplate">
<Option v-for="(item,index) in templateData" :key="index" :value="item.channelId">{{item.channelTitle}}</Option>
</Select>
2.方法中從ref取選中數據
insertTemplate(){
//console.log(this.currentTemplate)
//console.log(this.$refs.newText)
//得到選中value
console.log(this.$refs.newText.value)
//得到選中文本
console.log(this.$refs.newText.selectedSingle)
},