vue-menu icon indicating copy to clipboard operation
vue-menu copied to clipboard

Programmatic open the context menu.

Open liudonghua123 opened this issue 4 years ago • 3 comments

I want to open a dynamic context menu programmatic in the right click event handler of a button or component. How can I achieve this?

liudonghua123 avatar Apr 02 '20 13:04 liudonghua123

well, you can do it with ref's method. first, use vue-menu anywhere like this: <hsc-menu-style-white> <hsc-menu-context-menu ref="contextmenu"> <div class="box" style="display: none;"></div> <template slot="contextmenu"> <hsc-menu-item label="MenuItem 1" /> <hsc-menu-item label="MenuItem 2" /> <hsc-menu-item label="MenuItem 2"> <hsc-menu-item label="MenuItem 4" /> <hsc-menu-item label="MenuItem 5" /> </hsc-menu-item> </template> </hsc-menu-context-menu> <hsc-menu-style-white> second, you can use method[open] to open contextmenu, and then use mouse event to set contextmenu's position like this: <div @click="click"><div/> .... methods: { click(e) { const menu = this.$refs.contextmenu.$refs.menu; menu.open(); menu.setPosition(e.pageX, e.pageY, 'right'); } }

miyoosan avatar Nov 13 '20 04:11 miyoosan

I want to open a dynamic context menu programmatic in the right click event handler of a button or component. How can I achieve this?

more possible ways, you can try out the vue-menu instance

miyoosan avatar Nov 13 '20 04:11 miyoosan

@miyoosan Thanks, I will try your solution. 😄

liudonghua123 avatar Nov 13 '20 13:11 liudonghua123