el-select如何獲取下拉框選中l(wèi)abel和value的值
【示例1】
<templete slot-scope="scope"> <el-form-item :prop="'list'. + scope.$index + '.goodModularId'"> <!-- change事件中,會(huì)獲取到當(dāng)前選中的值(因?yàn)槟J(rèn)會(huì)將event參數(shù)傳遞過去; 如果想要傳遞多個(gè)值,change($event, "傳遞的其他值"),將“選中的當(dāng)前元素” 和 “傳遞的其他值” 一起傳遞過去 --> <el-select v-model="ruleForm.goodModularId" @change="getModularValue($event, scope.$index)" @clear="delModularValue(scope.$index)"> <el-option v-for="(item,index) in modularData" :key="index" :value="item.id" :label="item.name"></el-option> </el-select> </el-form-item> </templete> <script> data() { return { ruleForm: { list: [{ goodModularId: '', goodModular: '' }] } } } methods: { // 獲取value值給goodModular getModularValue(val,index) { let obj = this.modularData.find(item => item.id === val) // 判斷的時(shí)候可以直接寫obj而不需要以判斷對(duì)象是否為空的方式是因?yàn)椋喝绻也坏?,find方法返回的是undefined而不是空對(duì)象 if(obj) { this.ruleForm.list[index].goodModular = obj.name } else { this.ruleForm.list[index].goodModular = '' } } // 清空選項(xiàng)事件 delModularValue(index) { this.ruleForm.list[index].goodModular = '' } } </script>
【示例2】
<templete slot-scope="scope"> <el-form-item :prop="'list'. + scope.$index + '.goodModularId'"> <el-select v-model="ruleForm.goodModularId" @clear="delModularValue(scope.$index)"> <el-option v-for="(item,index) in modularData" :key="index" :value="item.id" :label="item.name" @click.native="getModularValue(item.id, scope.$index)"></el-option> </el-select> </el-form-item> </templete> <script> data() { return { ruleForm: { list: [{ goodModularId: '', goodModular: '' }] } } } methods: { getModularValue(val,index) { let obj = this.modularData.find(item => item.id === val) if(obj) { this.ruleForm.list[index].goodModular = obj.name } else { this.ruleForm.list[index].goodModular = '' } }, delModularValue(index) { this.ruleForm.list[index].goodModular = '' } } </script>
【示例3】
<el-form-item label="類別" prop="categoryId"> <el-select v-model="ruleForm.categoryId" @clear="clearCategory"> <el-option v-for="(item,index) in categoryOptions" :key="item.id" :value="item.id" :label="item.name" @click.native="getValue(item.name, categoryName)"></el-option> </el-select> </el-form-item>
getValue(val, type) { this.ruleForm[type] = val } clearCategory() { this.ruleForm.categoryName = '' }
總結(jié)
到此這篇關(guān)于el-select如何獲取下拉框選中l(wèi)abel和value值的文章就介紹到這了,更多相關(guān)el-select獲取下拉框選值內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue項(xiàng)目打包部署跨域的實(shí)現(xiàn)步驟
在前端 Vue 項(xiàng)目打包后,如果需要訪問另一個(gè)域名下的接口,由于瀏覽器的同源策略限制,會(huì)出現(xiàn)跨域問題,本文就介紹一下vue項(xiàng)目打包部署跨域的實(shí)現(xiàn)步驟,感興趣的可以了解一下2023-05-05vue項(xiàng)目中更改名字和圖標(biāo)的簡(jiǎn)單實(shí)現(xiàn)步驟
今天在寫vue項(xiàng)目時(shí)碰到的問題是怎么修改vue的網(wǎng)頁(yè)圖標(biāo),所以下面這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目中更改名字和圖標(biāo)的簡(jiǎn)單實(shí)現(xiàn),文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08基于vue監(jiān)聽滾動(dòng)事件實(shí)現(xiàn)錨點(diǎn)鏈接平滑滾動(dòng)的方法
本篇文章主要介紹了基于vue監(jiān)聽滾動(dòng)事件實(shí)現(xiàn)錨點(diǎn)鏈接平滑滾動(dòng)的方法,非常具有實(shí)用價(jià)值,有興趣的可以了解一下2018-01-01利用webstrom調(diào)試Vue.js單頁(yè)面程序的方法教程
這篇文章主要給大家介紹了利用webstrom調(diào)試Vue.js單頁(yè)面程序的方法教程,文中介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編一起來(lái)學(xué)習(xí)學(xué)習(xí)吧。2017-06-06vue截圖轉(zhuǎn)base64轉(zhuǎn)文件File異步獲取方式
這篇文章主要介紹了vue截圖轉(zhuǎn)base64轉(zhuǎn)文件File異步獲取方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03Vue3中reactive變量重新賦值無(wú)法響應(yīng)的3種處理方法
這篇文章主要給大家介紹了關(guān)于Vue3中reactive變量重新賦值無(wú)法響應(yīng)的3種處理方法,在Vue3中可以使用reactive函數(shù)將一個(gè)普通對(duì)象轉(zhuǎn)換為響應(yīng)式對(duì)象,需要的朋友可以參考下2023-08-08vue項(xiàng)目從node8.x升級(jí)到12.x后的問題解決
這篇文章主要介紹了vue項(xiàng)目從node8.x升級(jí)到12.x后的問題解決,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10vue開發(fā)中如何在js文件里使用pinia和組件同步
在JavaScript文件中封裝涉及到使用Pinia的方法時(shí),發(fā)現(xiàn)Pinia和組件內(nèi)容并不同步,二者的狀態(tài)是獨(dú)立的,解決辦法是,在新建對(duì)象的時(shí)候,將Pinia作為參數(shù)傳入,本文給大家介紹vue開發(fā)中如何在js文件里使用pinia和組件同步,感興趣的朋友一起看看吧2024-10-10