Home > Article > Web Front-end > What are the event modifiers in vue
Event modifiers in Vue allow extending the functionality of event handling functions: .stop: prevents events from bubbling. .prevent: Prevent default event behavior. .capture: Listen for events during the capture phase. .self: The event is only triggered when the target element is the current element. .once: Fire the event only once and remove the listener. .passive: Optimizes rendering performance, meaning the DOM is not modified. .native: Trigger native DOM events.
Event modifiers in Vue
Event modifiers in Vue allow us to add additional event handlers function to change its behavior. Here are some of the most commonly used event modifiers:
Usage example:
<code class="vue"><button @click.stop="myMethod">按钮</button></code>
In this example, the .stop
modifier is used to prevent the button click event from bubbling up to the parent components.
<code class="vue"><form @submit.prevent="myMethod">表单</form></code>
.prevent
Modifier is used to prevent the form submission default behavior.
<code class="vue"><div @click.capture="myMethod">容器</div></code>
.capture
Modifier is used to listen for click events in the container during the capture phase.
To use multiple modifiers, just concatenate them together:
<code class="vue"><a @click.stop.prevent="myMethod">链接</a></code>
This will prevent link navigation and prevent events from bubbling to the parent component.
The above is the detailed content of What are the event modifiers in vue. For more information, please follow other related articles on the PHP Chinese website!