2023-06-25 vue中獲取el-select 選中的label

參照?https://blog.csdn.net/m0_38038870/article/details/123418588

1.用Arry.find方法

<el-select v-model="value" placeholder="請選擇" @change="getLabel">

? ? <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">

? </el-option>

</el-select>

getLabel(value) {

? ? console.log(value);

? ? ? let obj = {};

? ? ? obj = this.options.find((item)=>{

? ? ? ? ? return item.value === value;

? ? ? });

? ? ? console.log(obj.label);

}

2.通過綁定原生click事件來進行傳參

<el-select v-model="value" placeholder="請選擇">

? ? <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" @click.native="labelClick(item.label)">

? ? </el-option>

? </el-select>

labelClick(data){

? console.log(data);

}

3.通過 $refs 拿到 el-select 組件實例,該實例擁有 selectedLabel 屬性,為當前選中的 label。

或者可以通過 selected 拿到選中的 option 的組件實例,擁有 label 和 value 兩個屬性。

<el-select ref="selectLabel" v-model="value" placeholder="請選擇" @change="getLabel">

? ? <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">

? ? </el-option>

getLabel(){

this.$nextTick(()=>{

? console.log(this.$refs.selectLabel.selectedLabel);

? console.log(this.$refs.selectLabel.selected.label);

})

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容