Ant?Design?of?Vue?select框獲取key和name的問題
Ant Design of Vue select框獲取key和name
加入label-in-value這個(gè)屬性
<a-form-item label="分類"> ? <a-select ? ? placeholder="請選擇分類" ? ? style="width: 100%" ? ? label-in-value ? ? v-decorator="['knowledgeunit', { rules: [{ required: true, message: '請選擇分類' }] }]" ? > ? ? <a-select-option v-for="(calssitem, index) in classflyData" :key="index" :value="calssitem.Code"> ? ? ? {{ calssitem.Name }} ? ? </a-select-option> ? </a-select> </a-form-item>
獲取到的value 就會變成 {key: 1, lable: '名字'} 的形式
獲取值的時(shí)候可以這樣獲取
this.addResourceForm.validateFields((err, values) => { ? ?if (err && this.newChange.length > 0) { ? ? ?return ? ?} ? ?const saveObj = {} ? ?saveObj.knowledgeunit = values.knowledgeunit.key // 獲取的值 ? ?saveObj.source = values.knowledgeunit.label ?// 獲取的名稱 ?})
我的記錄
還有一種方法
你如果想獲取怎個(gè)對象,怎么獲取呢?
<a-form-item label="分類"> ? <a-select ? ? placeholder="請選擇分類" ? ? style="width: 100%" ?? ?@change="onChange" ? ? v-decorator="['knowledgeunit', { rules: [{ required: true, message: '請選擇分類' }] }]" ? > ? ? <a-select-option v-for="(calssitem, index) in classflyData" :key="index" :value="calssitem.Code"> ? ? ? {{ calssitem.Name }} ? ? </a-select-option> ? </a-select> </a-form-item>
加一個(gè)onChange方法,根據(jù)下標(biāo)獲取對應(yīng)的對象
?onChange (item) { ? ?const obj = this.list[item] ? ?console.log(obj) ?}
Ant Design Vue使用select出現(xiàn)的問題
1.select下拉菜單滾動條滾動后,自動彈回到頂部
解決方法:
a-select-option 使用v-for渲染時(shí),key值不能重復(fù)或者為null
2.下拉列表在局部滾動時(shí)不跟隨,與select框分離
解決方法:
<a-select :getPopupContainer="(triggerNode)=>{ return triggerNode.parentNode || document.body;}"? >
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
axios解決高并發(fā)的方法:axios.all()與axios.spread()的操作
這篇文章主要介紹了axios解決高并發(fā)的方法:axios.all()與axios.spread()的操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11基于Vue3+TypeScript的全局對象的注入和使用詳解
這篇文章主要介紹了基于Vue3+TypeScript的全局對象的注入和使用,本篇隨筆主要介紹一下基于Vue3+TypeScript的全局對象的注入和使用,需要的朋友可以參考下2022-09-09avue實(shí)現(xiàn)自定義搜索欄及清空搜索事件的實(shí)踐
本文主要介紹了avue實(shí)現(xiàn)自定義搜索欄及清空搜索事件的實(shí)踐,主要包括對搜索欄進(jìn)行自定義,并通過按鈕實(shí)現(xiàn)折疊搜索欄效果,具有一定的參考價(jià)值,感興趣的可以了解一下2021-12-12