Vue事件修饰符可防止vs.停止 [英] Vue event modifiers prevent vs. stop

查看:120
本文介绍了Vue事件修饰符可防止vs.停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读有关事件的Vue文档时,他们提到了事件修饰符,例如阻止"或停止".他们提到停止:<!-- the click event's propagation will be stopped -->.我假设这将阻止事件起泡.那么prevent呢?它到底是做什么的?我假设它将阻止事件被触发两次(例如,双击).这些假设正确吗?我只是在网上找不到更多具体信息.

Reading the Vue documentation about events, they mention the event modifiers like prevent or stop. They mention that on stop: <!-- the click event's propagation will be stopped -->. I am assuming this will stop the event from bubbling. What about prevent. What does it exactly do? I am assuming it will prevent the event from being triggered twice (on a double click for example). Are these assumptions correct? I just couldn't find more specific info on the web.

我读到的东西:

  • https://vuejs.org/v2/guide/events.html
  • How to prevent/stop propagation of default event (click) in directive (vue 2.x)

推荐答案

.preventevent.preventDefault() –停止浏览器的默认行为(例如,当您在<form>中按<button type="submit">时重新加载)

.prevent or event.preventDefault() – It stops the browsers default behaviour (A example is reload when you hit <button type="submit"> in <form>)

.stopevent.stopPropagation() –它防止事件传播(或冒泡")DOM

.stop or event.stopPropagation() – It prevents the event from propagating (or "bubbling up") the DOM

.once-该事件最多触发一次

.once - The event will be triggered at most once

这篇关于Vue事件修饰符可防止vs.停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆