[element-ui] el-dropdown下拉菜单禁用项没有鼠标悬浮禁用样式

在这里插入图片描述
鼠标移入出现禁用样式,如下图,就是我们想要的效果
在这里插入图片描述

<template>
  <div id="app">
    <el-dropdown trigger="click" @command="handleCommand">
      <span class="el-dropdown-link">
        下拉菜单<i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="沙县小吃">
          沙县小吃
        </el-dropdown-item>
        <el-dropdown-item command="兰州拉面">
          兰州拉面
        </el-dropdown-item>
        <el-dropdown-item command="肉夹馍" disabled>
          肉夹馍
        </el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>
/deep/ .el-dropdown-menu__item.is-disabled {
  pointer-events: auto !important;
  cursor: not-allowed;
}

用js写禁用效果
在这里插入图片描述
在这里插入图片描述
如果我们再点击肉夹馍,我们会发现,打印出来的e的内容中的disabled的值就位true,所以发现规律了,就可以做控制了。即为:只有当e.disabled的值为false的时候(说明未被禁用),那么我们才在对应的回调中做相关的事情,否则就忽略

handleCommand(whichSelect,e){
      // 必须为禁用才能做一些事情
      if(whichSelect == "沙县小吃" && e.disabled == false){
        console.log("沙县小吃");
      }else if(whichSelect == "兰州拉面" && e.disabled == false){
        console.log("兰州拉面");
      }else if(whichSelect == "肉夹馍" && e.disabled == false){
        console.log("肉夹馍");
      }
    }

当然,如果自定义了command参数,也可以尝试接一下e,比如

<el-table>
  <el-table-column label="操作" align="center" fixed="right">
    <template slot-scope="scope">
      <el-button type="text" size="small">详情</el-button>
      <el-button type="text" size="small">编辑</el-button>
      <el-dropdown @command="handleCommand">
        <el-button type="text" size="small">
          更多操作<i class="el-icon-arrow-down el-icon--right" />
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item
            v-for="(item, index) in opBtns"
            :key="index"
            :command="{ command: item.value,row: scope.row }"
            :disabled="item.disabled"
            :divided="item.divided">{{ item.text }}</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </template>
  </el-table-column>
</el-table>

	 handleCommand(commandObj,e) { // 点击菜单项触发的事件回调
 		console.log(commandObj,e); //可以看一下e这个参数
      
    },


参考:

解决elementui中el-dropdown下拉菜单禁用项没有鼠标悬浮禁用样式

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值