2

I am trying to implement a solution which allows to attach 3 different handlers to an element, but none should trigger the others.

Using https://v2.vuejs.org/v2/guide/events.html as reference

<div @click.ctrl="methodA" @click="methodB" @contextmenu.ctrl="methodC"></div>

I've tried using .stop modifier randomly on each but I am unable to prevent methodA to also trigger methodB when I click. What would be the right way/modifiers to use or would the order I attach the handlers matter?

Edit

https://codepen.io/anon/pen/JVrGKo

2
  • This question could be improved by adding a codepen or fiddle to be able to reproduce the error and to make the task of helping you easier. Commented Apr 14, 2019 at 13:43
  • Added codepen example as requested Commented Apr 14, 2019 at 14:11

1 Answer 1

5

Interestingly enough, I created my own pen to test this and I could see the same thing you described in your questions happening in there as well, however with the pen you created I couldn't see that happening.

Anyhow, it does make sense that @click is triggered when @click.ctrl is triggered. But you can prevent that from happening by using the .exact modifier so the events get triggered only when the exact combination is used. Like this:

<div 
  @click.ctrl="methodA" 
  @click.exact="methodB"
  @contextmenu.ctrl="methodC"
></div>

Use this pen as an example

Let me know if that works.

Sign up to request clarification or add additional context in comments.

2 Comments

sad... I should have read the whole event page. I never saw the exact modifier before. Thanks for pointing it out.
NP! Happens to me all the time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.