Event Handling — Vue

v-on (@) const count = ref(0) const increment = () => count.value++ ---template--- Klik: {{ count }} Event Modifiers ---template--- ... Klik Inline Handler cons

v-on (@)

const count = ref(0)
const increment = () => count.value++

---template---
<button @click="increment">Klik: {{ count }}</button>

Event Modifiers

---template---
<!-- Cegah default behavior -->
<form @submit.prevent="handleSubmit">...</form>

<!-- Hanya sekali -->
<button @click.once="doSomething">Klik</button>

<!-- Enter key -->
<input @keydown.enter="search" />

Inline Handler

const name = ref("")

---template---
<input @input="(e) => name = e.target.value" />
<p>{{ name }}</p>

Yang akan kamu pelajari