I’d like to bind 2 mouse click events to a div field. One of them is a shift+click, the other is a regular click, eg.
<div @click.shift="aaa()" @click="bbb()">...</div>
The problem is when I shift+click on the div not only aaa() is executed, but bbb(), too.
I tried to use some modifiers, eg. @click.shift.stop or similar, but bbb() has been executed all the time I clicked on the div. How can I solve this without separating the 2 kind of click events in a single function, eg. ccc() that calls either aaa() or bbb()?
3
Answers
hope this helps!
I’d do it like so, add a single click handler which will dispatch the event accordingly.
What you are looking for is the "exact" modifier.
https://vuejs.org/guide/essentials/event-handling.html#exact-modifier
So this click event will trigger only if NO modifier were used, excluding it from executing when the @click.shift is triggered. Do note that this will also prevent alt+click, ctrl+click etc.