DEV Community

Narayan Adhikary
Narayan Adhikary

Posted on

3 3

Vue event modifiers

Imagine you want to implement events something like:

<Modal @ok.prevent="doNothing">
Modal Code
</Modal>
Enter fullscreen mode Exit fullscreen mode

That is when ok button of the modal is clicked, you want to prevent the event. In that case the prevent modifier can be implemented by code given below:

okButtonClickedMethod(e) {
   //First emit the ok event, then check if it is prevented or not
    emit('ok', e);
     //then hides modal
     if (e.defaultPrevented) {
          //emitted event is prevented now
     }
}
Enter fullscreen mode Exit fullscreen mode

**** Happy Coding ***

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay