Vue Events

Handle user actions with v-on.

✍️ 3 exercises + code challenge in this lesson
  • v-on:click="handler" or the shorthand @click="handler".
  • Inline statements: @click="count++"
  • Modifiers: @submit.prevent, @keyup.enter, @click.once
  • Methods are defined in the methods option.

Key Takeaways: Vue Events

Mastering Vue Events helps you write clean and reliable Vue.js code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

Vue Events Code Example

Vue.js
<script src="https://unpkg.com/vue@3.5.12/dist/vue.global.prod.js"></script>

<div id="app">
  <p>Count: {{ count }}</p>
  <button @click="count++">+1</button>
  <button @click="reset">Reset</button>
  <input @keyup.enter="say" placeholder="Type and press Enter">
  <p>{{ said }}</p>
</div>

<script>
  Vue.createApp({
    data() { return { count: 0, said: "" }; },
    methods: {
      reset() { this.count = 0; },
      say(e) { this.said = "You typed: " + e.target.value; }
    }
  }).mount("#app");
</script>
Free sign-in required · Google login available

Vue Events Practice Exercises

Check what you learned in “Vue Events”.

/ 3 solved
Fill in the blank

Shorthand for v-on:click.

<button ="count++">Add</button>
✓ Correct! Not quite. Try again.
Multiple choice

Which modifier calls event.preventDefault() on a form submit?

✓ Correct! Not quite. Try again.
Code challenge

Make the button increase count by 1. The check clicks it once and expects 1.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services