imengyu / vue3-context-menu

A very simple context menu component for Vue3 一个简洁美观简单的Vue3右键菜单组件
https://docs.imengyu.top/vue3-context-menu-docs/en/
MIT License
477 stars 65 forks source link

How to use in Nuxt3? #62

Open jeanscircuits opened 1 year ago

jeanscircuits commented 1 year ago

Help me to use in Nuxt 3 please.

ctissier commented 9 months ago

I know the question is a bit old, but just in case it helps, I made it work with Nuxt3 this way:

  1. Install the dependency

npm install @imengyu/vue3-context-menu

  1. Create a plugin to import the Component Globally :
// ~/plugins/vue3-context-menu.ts

import ContextMenu from '@imengyu/vue3-context-menu'
import '@imengyu/vue3-context-menu/lib/vue3-context-menu.css'

export default defineNuxtPlugin(nuxtApp => {
  nuxtApp.vueApp.use(ContextMenu)
})
  1. Implement the Component in your template

    
    <script lang="ts" setup>
    //...
    const contextMenuOptions = ref({})
    //...
    const showMenu = (event: MouseEvent)=>{
        contextMenuOptions.value = {
                zIndex:100,
                x: event.x,
                y: event.y
            }
        }
        menuVisible.value = true
        //event.stopPropagation()
    }
    
    const itemClicked(item){
       //do whatever you want when item is clicked
     } 
    //...
    </script>