43

right now, I need to add event.preventDefault() to all of my click events in my Vue.js buttons:

<button class="btn btn-primary" v-on:click="someAction($event)">Action</button></p>

methods: {
 someAction (e) {
   e.preventDefault()
   console.log('in some action')
 },
}

Does anyone know of a way have event.preventDefeault() be the default setting? Right now it's very annoying to have to include the event.preventDefault() in every click event.

Thanks in advance!

3
  • 1
    vuejs.org/v2/guide/events.html#Event-Modifiers Commented Mar 7, 2018 at 5:47
  • thanks - to confirm, in my case I should use v-on:click.stop="someMethod" right? Commented Mar 7, 2018 at 5:50
  • .prevent if event.preventDefault() is what you want. .stop if event.stopPropagation() is what you want. Commented Mar 7, 2018 at 5:51

1 Answer 1

75

You can use prevent modifier:

@click.prevent="YourMethod"

You can look event modifier for more information.

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

Comments

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.