Contextmenu 右键菜单

... 2022-5-10 Less than 1 minute

# Contextmenu 右键菜单

Tips

2.9.8+

  • 张三
  • 李四
  • 王五

利用v-contextmenu指令传入相关参数即可

 <ul>
  <li v-for="(item,index) in list" :key="index" class="el-dropdown-menu__item"
    v-contextmenu="{id:'dialog',event:handleEvent,value:item,hide:handleHide}">
    {{item.name}}
  </li>
</ul>
 <ul class="el-dropdown-menu el-popper" id="dialog" style="display:none">
    <li class="el-dropdown-menu__item" @click="handleClick1">
      <i class="el-icon-eleme"></i>菜单1
    </li>
    <li class="el-dropdown-menu__item" @click="handleClick2">
      <i class="el-icon-user"></i>菜单2
    </li>
    <li class="el-dropdown-menu__item" @click="handleClick3">
      <i class="el-icon-goods"></i>菜单3
    </li>
    <li class="el-dropdown-menu__item el-dropdown-menu__item--divided" @click="handleClick4">
      <i class="el-icon-circle-check"></i>菜单4
    </li>
    <li class="el-dropdown-menu__item" @click="handleClick4">
      菜单5
    </li>
  </ul>
<script>
export default {
  data() {
      return {
        form: {},
        list: [{
          name: '张三'
        }, {
          name: '李四'
        }, {
          name: '王五'
        }]
      }
  },
  created() {
    setTimeout(() => {
      this.list[0].name = 'small'
    }, 1000)
  },
  methods:{
    handleHide(row) {
      this.$message.success('隐藏回调信息' + JSON.stringify(row))
    },
    handleEvent(row, done) {
      this.form = row;
      done();
      this.$message.success('回调信息' + JSON.stringify(row))
    },
    handleClick1() {
      this.$message.success('菜单1' + JSON.stringify(this.form))
    },
    handleClick2() {
      this.$message.success('菜单2' + JSON.stringify(this.form))
    },
    handleClick3() {
      this.$message.success('菜单3' + JSON.stringify(this.form))
    },
    handleClick4() {
      this.$message.success('菜单4' + JSON.stringify(this.form))
    },
  }
}
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Expand Copy
Last update: April 19, 2024 11:23
Contributors: smallwei
您正在浏览基于 Vue 2.x 的 Avue 文档; 点击这里 查看 Vue 3.x 的升级版本