效果图-右键菜单

npm install vue-contextmenujs
yarn add vue-contextmenujs
<script src="https://unpkg.com/vue-contextmenujs/dist/contextmenu.umd.js">
src/main.js
import Contextmenu from "vue-contextmenujs"
Vue.use(Contextmenu);
CDN引入则不需要Vue.use(Contextmenu)
textMenu.vue
右键
引入
HelloWorld.vue
打开控制台,查看元素即可查看到菜单的各个 class 名称。最外层的 class 为上面的customClass属性设置的值,样式可根据需求自行调整。
效果

菜单会在点击左键或者滚轮滚动时自动销毁,同时也可调用this.$contextmenu.destroy()在其他场景自行销毁 。
| 属性 | 描述 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| items | 菜单结构信息 | MenuItemOptions[] | — | — |
| event | 鼠标事件信息 | Event | — | — |
| x | 菜单显示X坐标, 存在event则失效 | number | — | 0 |
| y | 菜单显示Y坐标, 存在event则失效 | number | — | 0 |
| zIndex | 菜单样式z-index | number | — | 2 |
| customClass | 自定义菜单class | string | — | — |
| minWidth | 主菜单最小宽度 | number | — | 150 |
| 属性 | 描述 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| label | 菜单项名称 | string | — | — |
| icon | 菜单项图标, 生成元素 | string | — | — |
| disabled | 是否禁用菜单项 | boolean | — | false |
| divided | 是否显示分割线 | boolean | — | false |
| customClass | 自定义子菜单class | string | — | — |
| minWidth | 子菜单最小宽度 | number | — | 150 |
| onClick | 菜单项点击事件 | Function() | — | — |
| children | 子菜单结构信息 | MenuItemOptions[] | — | — |