select下拉框组件禁用选项值怎么实现

效果如图
在这里插入图片描述

背景需求

下拉框的数据选项值是通过接口请求过来的,当时没有想明白将disabled为true写在哪里
接口直接将数据渲染出来了,就是在后面继续再做判断;这个与当时的时间判断出数据是大同小异;因此不用将问题复杂化,这样做还少写了@change这个切换值的方法了。

源代码

 <!-- //指定部门主管的多选框 -->
 <template v-if="orderConfig.reportAuditType == 3">
     <el-select
       v-model="orderConfig.reportDesignatedDept"
       clearable
       :placeholder="$t('commons.selectPlease')"
       :key="'reportDesignatedDept'"
       @change="showTip"
     >
       <el-option
         v-for="item in deptList"
         :key="item.deptId"
         :label="item.deptName"
         :value="item.deptId"
         :disabled="item.disabled"
       >
       </el-option>
     </el-select>
   </template>
//这个是请求下拉框的数据的请求方法
getEmployeeList(projectId) {
      return getOwnProject(projectId).then((res) => {
        getEmployeeList({ companyId: res.companyId }).then((response) => {
          this.empList = response;
        });
        //这个是请求下拉框的数据的请求方法
        selectDeptByCompanyId({ companyId: res.companyId }).then((response) => {
        //这里是所有的下拉框选项数据
          this.deptList = response;
          //遍历 this.deptList 负责人为空deptHeadId == null 即禁用
          for (let i = 0, length = this.deptList.length; i < length; i++) {
               if (this.deptList[i].deptHeadId == null) {
                this.deptList[i].disabled=true;
               }
          }
        });
      });
    },
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序媛夏天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值