• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
念念不忘i
博客园    首页    新随笔    联系   管理    订阅  订阅
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>

 

posted on 2021-10-24 20:31  念念不忘i  阅读(1058)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3