v-on lyssnar på DOM-händelser (klick, inmatning, tangenttryckningar) och kör en hanterare. Dess förkortning är @.
<script setup>
import { ref } from "vue";
const count = ref(0);
function increment() { count.value++; }
</script>
<template>
<button v-on:click="increment">Full syntax</button>
<button @click="increment">Shorthand (idiomatic)</button>
<button @click="count++">Inline expression</button>
<button @click="increment($event, 'extra')">Pass args + the event</button>
</template>
Du kan skicka ett metodnamn, ett inline-uttryck eller anropa en metod med argument. Det ursprungliga händelseobjektet är tillgängligt som .
