Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

v-contextmenus

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

v-contextmenus

Vue 右键菜单功能

  • 0.0.2
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

VContextmenus

右键菜单功能

使用方式

  1. 安装
yarn add v-contextmenus
  1. 在 vues 的 state 中添加共享状态与方法

请先确保你有使用 vuex

{
	state: {
		contextmenus: {
			// 状态
			show: true
			// 数据
			data: {},
			// 事件
			evt: null
		}
	},
	mutaions: {
		// 设置方法
		setContextmenu (state, data) {
			if (Object.keys(data).length > 1) {
				state.contextmenu = data
			} else {
				state.contextmenu.show = data.show
			}
		}
	}
}
  1. 在页面中调用组件
<template>
	<main>
		<!-- 绑定事件 -->
		<div @contextmenu.prevent="rightClick"></div>

		<!-- 引用 -->
		<VContextmenus></VContextmenus>
	</main>
</template>

<script>
	// 引入 store
	import store from '../assets/js/store'
	// 引入
	import VContextmenus from '../components/VContextmenus'

	export default {
		components: {
			VContextmenus
		},
		data () {
			return {
				// 菜单内容
				menu: [ ... ]
			}
		},
		methods: {
			// 自定义事件
			rightClick (evt) {
				store.commit('setContextmenu', {
					data: this.menu, evt
				})
			}
		}
	}
</script>

事件方法

  • store.commit('setContextmenu', {data, evt})

@data 菜单内容 @evt 鼠标事件

展示菜单功能

完整示例

将 demo 文件放到你的 vue webpack 项目中,替换其下的 src

FAQs

Package last updated on 21 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc