DEV Community

Narayan Adhikary
Narayan Adhikary

Posted on

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)