vuejs
/

Vue Events

Last Sync: Today

On this page

13
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

vuejs

Vue Events

What are Events in Vue?

Events in Vue are used to handle user interactions such as clicks, typing, and form submissions.

Basic Event Handling

HTMLRead-only
1
<button @click="handleClick">Click</button>

Inline Event

HTMLRead-only
1
<button @click="count++">Increment</button>
<p>{{ count }}</p>

Methods Example

JavaScriptRead-only
1
methods: {
  handleClick() {
    alert('Clicked');
  }
}

Passing Arguments

HTMLRead-only
1
<button @click="greet('Vue')">Greet</button>

Event Object

HTMLRead-only
1
<button @click="handleClick($event)">Click</button>

Emitting Events (Child to Parent)

JavaScriptRead-only
1
this.$emit('customEvent', data);

Listening to Emitted Events

HTMLRead-only
1
<child-component @customEvent="handleEvent"></child-component>

Event Modifiers

  • .stop → Stop propagation
  • .prevent → Prevent default action
  • .once → Trigger once
  • .self → Only trigger on element itself

Keyboard Events

HTMLRead-only
1
<input @keyup.enter="submit">

Best Practices

  • Use methods for complex logic
  • Use emit for component communication
  • Keep event handlers simple
  • Use modifiers effectively

Common Mistakes

  • Writing complex logic inline
  • Not using emit for communication
  • Ignoring event modifiers
  • Incorrect event naming

Conclusion

Vue events provide a powerful way to handle user interactions and component communication efficiently.

Try it yourself

<button @click="count++">Click</button>
<p>{{ count }}</p>

Test Your Knowledge

Q1
of 3

Event shorthand?

A
#
B
@
C
:
D
$
Q2
of 3

Child to parent?

A
v-model
B
$emit
C
v-bind
D
v-if
Q3
of 3

Prevent default?

A
.stop
B
.prevent
C
.once
D
.self

Frequently Asked Questions

What is @click?

It listens to click events.

What is $emit?

It sends events from child to parent.

What are event modifiers?

They modify event behavior like prevent or stop.

Previous

vue props

Next

vue slots

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.