v-on Event Modifiers
.stop, .prevent, .self, .once, .capture, .passive — when and why to use each modifier.
v-on Event Modifiers is a free Vue Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Cleaner Event Handling
The v-on directive (shorthand @) attaches event listeners. Event modifiers are suffixes that handle common DOM chores like stopping propagation or preventing defaults, so your handlers stay focused on logic.
The Problem Modifiers Solve
Without modifiers you sprinkle DOM boilerplate inside handlers: calling event.preventDefault() or event.stopPropagation(). Modifiers move that into the template declaratively.
.stop for stopPropagation
.stop stops the event from bubbling to parent elements — equivalent to calling event.stopPropagation().
<!-- inner click will not reach the outer handler -->
<div @click="onOuter">
<button @click.stop="onInner">Click</button>
</div>.prevent for preventDefault
.prevent calls event.preventDefault(). The classic use is stopping a form from reloading the page on submit.
<form @submit.prevent="onSubmit">
<button type="submit">Save</button>
</form>Chaining Modifiers
You can combine modifiers. Order matters — they apply left to right.
<a @click.stop.prevent="onClick">Link</a>.self: Only the Element Itself
.self fires the handler only if the event target is the element itself, not a child that bubbled up. Great for overlay backgrounds.
<!-- closes only when the backdrop itself is clicked -->
<div class="backdrop" @click.self="close">
<div class="modal">...</div>
</div>Key Modifiers
For keyboard events you can listen to specific keys. @keyup.enter fires only when the Enter key is released.
<input @keyup.enter="search" />More Key Modifiers
Vue provides aliases for common keys: .enter, .esc, .tab, .delete, .space, and arrow keys like .up and .down.
<input @keyup.esc="cancel" @keyup.up="previous" />.once: Fire a Handler Only Once
.once runs the handler at most one time, then removes the listener. Useful for one-time actions like a welcome dismissal.
<button @click.once="initialize">Start</button>.passive for Scroll Performance
.passive tells the browser the handler will not call preventDefault(). This lets the browser scroll smoothly without waiting, improving performance on touch and scroll events.
<div @scroll.passive="onScroll">...</div>Choosing the Right Modifier
.stop— stop bubbling..prevent— block default behavior..self— ignore bubbled child events..once— run once..passive— never prevent default; better scroll perf.
Note: never combine .passive with .prevent — they contradict.
Quick Check
Pick the right modifier.
Recap
Event modifiers keep handlers clean:
.stop= stopPropagation,.prevent= preventDefault..selffires only on the element itself.- Key modifiers like
.entertarget specific keys. .onceruns a handler one time;.passiveimproves scroll performance.
Frequently asked questions
Is the “v-on Event Modifiers” lesson free?
Yes — the full text of “v-on Event Modifiers” is free to read here on the web, and the Vue Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Vue Academy course, upgrade to CoddyKit PRO.
What will I learn in “v-on Event Modifiers”?
.stop, .prevent, .self, .once, .capture, .passive — when and why to use each modifier. You practise Vue Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Vue Academy?
No prior experience is required. Vue Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “v-on Event Modifiers” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Vue Academy lesson?
Yes. Every Vue Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.