Vue 事件修饰符阻止 vs. 停止 [英] Vue event modifiers prevent vs. stop
问题描述
阅读有关事件的 Vue 文档,他们提到了诸如 prevent 或 stop 之类的事件修饰符.他们提到在停止时:<!-- click 事件的传播将被停止-->
.我假设这将阻止事件冒泡.prevent
怎么样.它究竟有什么作用?我假设它会阻止事件被触发两次(例如双击).这些假设正确吗?我只是在网上找不到更具体的信息.
我读到了什么:
.prevent
or event.preventDefault()
– 它停止浏览器的默认行为(一个例子是当您在 ) 中点击
时重新加载
.stop
或 event.stopPropagation()
– 防止事件传播(或冒泡")DOM
.once
- 事件最多触发一次
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.
What I read:
- https://vuejs.org/v2/guide/events.html
- How to prevent/stop propagation of default event (click) in directive (vue 2.x)
.prevent
or event.preventDefault()
– It stops the browsers default behaviour (A example is reload when you hit <button type="submit">
in <form>
)
.stop
or event.stopPropagation()
– It prevents the event from propagating (or "bubbling up") the DOM
.once
- The event will be triggered at most once
这篇关于Vue 事件修饰符阻止 vs. 停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!