vue事件修饰符(stop,prevent,self,once)

Vue.js 为 v-on 提供了事件修饰符。修饰符是由点开头的指令后缀来表示的。

  • .stop :阻止事件冒泡
  • .prevent :阻止默认事件发生,比如超链接的默认跳转、表单的提交(重点)
  • .self :只有元素自身触发事件才执行。(子元素的事件冒泡来的不执行)
  • .once :只执行一次

举例:

//使用prevent,点击提交之后调用updateUser()方法
<form @submit.prevent="updateUser">
  用户名:<input type="text" v-model="user.name"/>
  密码:<input type="text" v-model="user.pwd"/>
  <button>确定修改</button>

猜你喜欢

转载自blog.csdn.net/qq_43521500/article/details/121008999