Vue+Element UI一個下拉框傳字典值和對應字典Label


<el-select @change="getDeptName" v-model="form.deptCode">
     <el-option v-for="item in deptList" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue"></el-option>
</el-select>
<script>
    export default {
        data(){
            deptList:[
                             {dictValue:1,dictLabel:'研發部門 '},
                             {dictValue:2,dictLabel:'銷售部門 '}
                        ]
            form:{
                deptCode: null,
                deptName: null,
             }
        },
       methods:{
      //找字典值對應Label名稱方法 可全局掛載到main.js項目開發中超實用       checkDict(list, key) {
        // list--字典列表 key --字典值         
var obj = list.find(item => {return item.dictValue == key}) if (!obj) { return key } else { return obj.dictLabel } }, getDeptName() { this.$set( this.form,"deptName",this.checkDict(this.deptList, this.form.deptCode)); }, } } </script>

 


免責聲明!

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



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