elementui右键菜单实现

el-table添加@row-contextmenu="rightClick"

// table的右键点击当前行事件
    rightClick(row, column, event) {
      // 阻止浏览器右键默认
      event.preventDefault();
      // 当前行在编辑状态时 或者 有正在编辑的行
      if (!(this.currentRow.showRow || row.showRow) && row.patrolStatus === '未进行') {
        this.foo();
        // 定义变量接收该节点所对应的对象
        this.currentRow = row;
        this.menuVisible = true;
        // 获取当前右键点击table下标
        this.data.forEach((item, index) => {
          if (item.id === row.id) {
            this.currentRowIndex = index;
            return false;
          }
        });
        // 监听事件鼠标点击事件,若点击则隐藏菜单
        document.addEventListener('click', this.foo);
        this.$refs.card.$el.style.left = `${event.clientX + 20}px`;
        this.$refs.card.$el.style.top = `${event.clientY - 100}px`;
        
      }
    },
    foo() {
      this.menuVisible = false;
      // 及时关掉监听
      document.removeEventListener('click', this.foo);
    },

菜单样式不管,使用el-card

<el-card class="box-card" ref="card" v-show="menuVisible" >
          <div class="edit" @click="edit()">
            编辑
          </div>
          <div class="delete" @click="remove()" >
            删除
          </div>
        </el-card>

保存当前行数据,点击调用card上的模拟菜单绑定的方法~注意间隙。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值