Let's break it down simply
@click is shorthand for v-on:click. You can write a simple assignment as an inline handler, but for anything more involved, write a dedicated function. Modifiers like .prevent, .stop, and .enter keep your DOM logic clean.
vue
<script setup>
import { ref } from 'vue'
const name = ref('')
function save() {
console.log(`Saved: ${name.value}`)
}
</script>
<template>
<form @submit.prevent="save">
<input v-model="name" @keyup.esc="name = ''">
<button>Save</button>
</form>
</template>You should see
Saved: MyaTry it yourself
Build a form that adds a new item when you press Enter and clears the input when you press Escape.
Event Handling — Vue.js