vue中同時獲取select下拉框的值和文本(Key,Value)

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)

},

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章