Vue 2 Context Menu Component

2.0.6 · abandoned · verified Sun Apr 19

This package, `vue-context-menu`, provides a simple context menu component specifically designed for Vue 2 applications. It allows developers to easily integrate custom right-click menus into their Vue 2 projects, attaching them to specific DOM elements. The latest stable version is 2.0.6, last published in July 2017, indicating that the project is effectively abandoned with no active maintenance or updates. Its release cadence was sporadic and has ceased. Key differentiators at the time were its straightforward API for attaching menus via `v-ref` and handling `contextmenu.prevent` events. However, it lacks features common in modern alternatives like built-in theming, nested menus, or programmatic API options, and is fundamentally incompatible with Vue 3. For new projects or those using Vue 3, alternative context menu libraries are highly recommended.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to integrate `vue-context-menu` into a Vue 2 component, preventing the browser's default context menu and opening the custom one.

<template>
  <div @contextmenu.prevent="$refs.ctxMenu.open">
    Right-click me for a context menu!
  </div>

  <context-menu id="my-context-menu" ref="ctxMenu">
    <li @click="doSomething('Option 1 clicked')">Option 1</li>
    <li class="disabled">Option 2 (Disabled)</li>
    <li @click="doSomething('Option 3 clicked')">Option 3</li>
  </context-menu>
</template>

<script>
import contextMenu from 'vue-context-menu'

export default {
  name: 'ContextMenuDemo',
  components: { contextMenu },
  methods: {
    doSomething(message) {
      alert(message)
      // Optionally close the menu after action
      this.$refs.ctxMenu.close()
    }
  }
}
</script>

<style>
/* Basic styling for the context menu for visibility */
#my-context-menu {
  border: 1px solid #ccc;
  background: white;
  box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
  list-style: none;
  padding: 5px 0;
  margin: 0;
  position: fixed;
  z-index: 1000;
}
#my-context-menu li {
  padding: 8px 15px;
  cursor: pointer;
}
#my-context-menu li:hover:not(.disabled) {
  background-color: #f0f0f0;
}
#my-context-menu li.disabled {
  color: #aaa;
  cursor: not-allowed;
}
</style>

view raw JSON →