1.4.11 • Published 1 year ago

vue-contextmenujs v1.4.11

Weekly downloads
279
License
MIT
Repository
github
Last release
1 year ago

Vue Contextmenu (Vue2)

npm.io npm.io

Vue 原生实现右键菜单组件, 零依赖

sample

在线演示

快速安装

npm 安装

npm install vue-contextmenujs

yarn add vue-contextmenujs

CDN

<script src="https://unpkg.com/vue-contextmenujs/dist/contextmenu.umd.js">

使用

CDN引入则不需要 Vue.use(Contextmenu)

测试中使用的是element-ui图标

import Contextmenu from "vue-contextmenujs"
Vue.use(Contextmenu);

// 在组件中调用显示菜单 // this.$contextmenu(options:MenuOptions); // 鼠标点击或滚轮自动销毁, 也可手动销毁 // this.$contextmenu.destroy();

// 去除浏览器默认菜单 // event.preventDefault();

```html
<template>
  <div id="app" style="width:100vw;height:100vh" @contextmenu.prevent="onContextmenu"></div>
</template>

<script>
export default {
  methods: {
    onContextmenu(event) {
      this.$contextmenu({
        items: [
          {
            label: "返回(B)",
            onClick: () => {
              this.message = "返回(B)";
              console.log("返回(B)");
            }
          },
          { label: "前进(F)", disabled: true },
          { label: "重新加载(R)", divided: true, icon: "el-icon-refresh" },
          { label: "另存为(A)..." },
          { label: "打印(P)...", icon: "el-icon-printer" },
          { label: "投射(C)...", divided: true },
          {
            label: "使用网页翻译(T)",
            divided: true,
            minWidth: 0,
            children: [{ label: "翻译成简体中文" }, { label: "翻译成繁体中文" }]
          },
          {
            label: "截取网页(R)",
            minWidth: 0,
            children: [
              {
                label: "截取可视化区域",
                onClick: () => {
                  this.message = "截取可视化区域";
                  console.log("截取可视化区域");
                }
              },
              { label: "截取全屏" }
            ]
          },
          { label: "查看网页源代码(V)", icon: "el-icon-view" },
          { label: "检查(N)" }
        ],
        event,
        //x: event.clientX,
        //y: event.clientY,
        customClass: "custom-class",
        zIndex: 3,
        minWidth: 230
      });
      return false;
    }
  }
};
</script>

自定义样式

/* custom */
.custom-class .menu_item__available:hover,
.custom-class .menu_item_expand {
  background: #ffecf2 !important;
  color: #ff4050 !important;
}

/* antd */
.antd-theme.menu {
  border-radius: 2px !important;
}
.antd-theme .menu_item {
  color: #000000d9 !important;
}
.antd-theme .menu_item__available:hover {
  background: #f5f5f5 !important;
}
.antd-theme .menu_item_expand {
  font-weight: 600 !important;
  background-color: #e6f7ff !important;
}

/* material */
.material-theme.menu {
  box-shadow: 0px 5px 5px -3px rgba(0, 0, 0, 0.2),
    0px 8px 10px 1px rgba(0, 0, 0, 0.14), 0px 3px 14px 2px rgba(0, 0, 0, 0.12) !important;
}
.material-theme .menu_item {
  color: #000000de !important;
}
.material-theme .menu_item__available:hover,
.material-theme .menu_item_expand {
  background: rgba(0, 0, 0, 0.04) !important;
}

参数说明

MenuOptions

属性描述类型可选值默认值
items菜单结构信息MenuItemOptions[]
event鼠标事件信息Event
x菜单显示X坐标, 存在event则失效number0
y菜单显示Y坐标, 存在event则失效number0
zIndex菜单样式z-indexnumber2
customClass自定义菜单class, 使用.custom-class .menu_item定位菜单项string
minWidth主菜单最小宽度number150

MenuItemOptions

属性描述类型可选值默认值
label菜单项名称string
icon菜单项图标, 生成<i class="icon"></i>元素string
disabled是否禁用菜单项booleanfalse
hidden是否隐藏菜单项booleanfalse
divided是否显示分割线booleanfalse
customClass自定义子菜单class, 使用.custom-class .menu_item定位菜单项string父级菜单customClass
minWidth子菜单最小宽度number150
onClick菜单项点击事件Function()
children子菜单结构信息MenuItemOptions[]
ckaix_coreckaix_core_1@infinitebrahmanuniverse/nolb-vue-co@everything-registry/sub-chunk-3077wavezhu-halo-adminsbs-approvetheonelims-layouttheonelims-txformvtuzx-adminvue-flow-draggablevue-drag-groupidejslow-code-demohs-sky-uihx-data-accesshalo-admingy-mainjic_data_web-devjic_data_web_dedvjicdatahely-data-room-uimyapp-dataroompackage-yysd-uioutshine-haloadminnewlife-componentspoc-ui@binlinux/dash-board-ui@cladder/cladder-core@cladder/cladder-micro-core@cladder/core@dhcc-t/rddc-core@dhccmobile/bjitic-common@dhccmobile/core-zhdb@dhccmobile/core-ztj@dhccmobile/main-core@dhccmobile/perpetual-calendar@dhccmobile/rddc-core@dhccmobile/rddc-ht-core@dhccmobile/rddc-ht-cust-core@dhccmobile/rddc-zl-core@dhccmobile/shtrust-core@dhccmobile/zlrz-cust-core@crtc_trust/coreyj.allinonexw-dashboardyg-data-room-uizhu_my_projectztwxdata-room-ui@ebtrust_npm/core@gcpaas/dash-board-ui@gcpaas/data-room-ui@liuwanbin/cdb-core@mingo_zh/data-room-ui@jx3box/jx3box-editor@shixinclearboth/comfullcalendar@shixinclearboth/more_fullcalendar_timelineadmanai-svg-editorcdb_coredata-room-ui-sassdata-room-ui-zyhdata-test-001cunw-demo-uidh_coredkgsdkgs-sdkedit-page2022corgi-admindpvs-uidoway-comsform-ant-initgd-imgb_webgc-starter-bigscreen-designgc-starter-bigscreen-uigc-starter-dashboard-uifxsk-designer-afxsk-designer-bfxsk-designer-cfxsk-designer-dfxsk-designer-vfxsk-designer-wfxsk-designer-xfxsk-designer-efxsk-designer-ffxsk-designer-gfxsk-designer-hfxsk-designer-ifxsk-designer-jfxsk-designer-kfxsk-designer-lfxsk-designer-mfxsk-designer-nfxsk-designer-tfxsk-designer-u@vipl520/dkgs-ui@viva3la3vida/base-render
1.4.11

1 year ago

1.4.10

1 year ago

1.4.9

2 years ago

1.4.8

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.4.7

2 years ago

1.3.13

4 years ago

1.3.11

4 years ago

1.3.12

4 years ago

1.3.10

4 years ago

1.3.9

5 years ago

1.3.8

5 years ago

1.3.7

5 years ago

1.3.6

5 years ago

1.3.5

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.1.2

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago