vue select 獲取value和lable操作


vue select控件在選擇時需要把id和name兩個值都獲取到,實現方案如下:

select控件代碼

 <FormItem label="物資類型:" prop="supplyType">
 <Select v-model="detailData.supplyType" :label-in-value="true" placeholder="請選擇物資類型" @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
},

下拉組件綁定數據源

 supplyTypeList[
   {
     "id": 45,
     "dictionaryName": "辦公用品",
     "dictionaryCode": "nofficeSupplies"
   }
 ]

補充知識:vue選擇器select獲取選中項的value和id

今天在nuxt項目中使用element-ui的選擇器時,有個需求要獲取options的id和label。

做法如下:

html代碼

 

 在methods中:

 

 文章來源:https://www.jb51.net/article/194335.htm

  

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM