<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>