Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue JS : right click event directive

I know these vue event handlers:

@click : mouse left-click @dblclick : mouse double click 

What could be the handler/directive to detect a right-click? Need to implement a custom Context menu in Vue Tree view.

like image 660
Praveen Kamath Avatar asked Apr 14 '16 12:04

Praveen Kamath


1 Answers

<button @contextmenu="handler($event)">r-click</button>  methods : {     handler: function(e) {         //do stuff         e.preventDefault();      } } 

@contextmenu will do the trick. The preventDefault is to avoid showing the default context menu.

Shorter, as indincated in the comment :

<button @contextmenu.prevent="handler">r-click</button> 

Now the prevent modifier takes care preventing default behaviour.

Edit: For this to work with vue components, add a .native event modifier.

<custom @contextmenu.native="handler"></custom> 
like image 142
zxzak Avatar answered Sep 20 '22 22:09

zxzak