Vue Academy · Lesson

v-on Event Modifiers

.stop, .prevent, .self, .once, .capture, .passive — when and why to use each modifier.

Lesson 2 of 413 steps

v-on Event Modifiers is a free Vue Academy lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, and your progress syncs across the web and the CoddyKit app. The Vue Academy course includes 4 lessons in total.

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.
  • .self fires only on the element itself.
  • Key modifiers like .enter target specific keys.
  • .once runs a handler one time; .passive improves scroll performance.
Free to start

Learn HTML with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
42
Lessons
156

Frequently Asked Questions

Is the “v-on Event Modifiers” lesson free?

Yes — any 3 lessons of the Vue Academy learning path, including “v-on Event Modifiers”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Vue Academy course includes 4 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.

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.

All lessons in this course

  1. v-model: Two-Way Binding Internals
  2. v-on Event Modifiers
  3. v-bind Dynamic and Multiple Bindings
  4. Writing Custom Directives
← Back to Vue Academy