Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmatic open the context menu. #28

Open
liudonghua123 opened this issue Apr 2, 2020 · 3 comments
Open

Programmatic open the context menu. #28

liudonghua123 opened this issue Apr 2, 2020 · 3 comments

Comments

@liudonghua123
Copy link

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?

@miyoosan
Copy link

miyoosan commented Nov 13, 2020

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
Copy link

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

@liudonghua123
Copy link
Author

@miyoosan Thanks, I will try your solution. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants