Vuejs - automatic event.preventDefault()

拟墨画扇 提交于 2019-12-23 07:59:35

问题


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!


回答1:


You can use prevent modifier:

@click.prevent="YourMethod"

You can look event modifier for more information.



来源:https://stackoverflow.com/questions/49144791/vuejs-automatic-event-preventdefault

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!