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!
The other way we can achieve preventing the default form submission behaviour is by attaching a submit event with the prevent modifier to the starting form tag in the template. This will prevent the page from reloading when the submit button is pressed as well.
Specifically, we can use stop event modifier. . stop will stop the event propagation.
prevent is a modifier for v-on:click . Another handy modifier is . self , which tells Vue to only evaluate v-on:click if the element itself is clicked, as opposed to one of its children. For example, Vue only calls the below v-on:click handler when you click on the outer div , not the inner div .08-Jul-2020.
You can use prevent
modifier:
@click.prevent="YourMethod"
You can look event modifier for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With