vue select 獲取value和lable操作
vue select控件在選擇時(shí)需要把id和name兩個(gè)值都獲取到,實(shí)現(xiàn)方案如下:
select控件代碼
<FormItem label='物資類型:' prop='supplyType'> <Select v-model='detailData.supplyType' :label-in-value='true' placeholder='請(qǐng)選擇物資類型' @on-change='getVendorId'> <Option v-for='item in supplyTypeList' :value='item.id' :key='item.id' :lable='item.dictionaryName'>{{ item.dictionaryName }} </Option> </Select> </FormItem>
change事件
getVendorId: function (val) { let that = this; that.detailData.supplyType=val.value;//獲取label that.detailData.supplyTypeName=val.label;//獲取value},
下拉組件綁定數(shù)據(jù)源
supplyTypeList[ { 'id': 45, 'dictionaryName': '辦公用品', 'dictionaryCode': 'nofficeSupplies' } ]
補(bǔ)充知識(shí):vue選擇器select獲取選中項(xiàng)的value和id
今天在nuxt項(xiàng)目中使用element-ui的選擇器時(shí),有個(gè)需求要獲取options的id和label。
做法如下:
html代碼
在methods中:
這樣就可以精準(zhǔn)的獲取到啦,希望可以幫到你呀!
以上這篇vue select 獲取value和lable操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. CSS hack用法案例詳解2. css進(jìn)階學(xué)習(xí) 選擇符3. CSS Hack大全-教你如何區(qū)分出IE6-IE10、FireFox、Chrome、Opera4. 使用css實(shí)現(xiàn)全兼容tooltip提示框5. 低版本IE正常運(yùn)行HTML5+CSS3網(wǎng)站的3種解決方案6. 使用純HTML的通用數(shù)據(jù)管理和服務(wù)7. css代碼優(yōu)化的12個(gè)技巧8. 告別AJAX實(shí)現(xiàn)無(wú)刷新提交表單9. HTML DOM setInterval和clearInterval方法案例詳解10. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)
