Mtoto anawasiliana juu kwa zazi lake kwa kutoa matukio. Zazi hukinza matukio hayo kwa @event-name. Hii inahitimisha mtiririko wa data wa Vue wa njia moja: props chini, matukio juu.
Kutoa kutoka kwa sehemu ya mtoto
<!-- TodoItem.vue -->
<script setup>
const props = defineProps({ todo: Object });
const emit = defineEmits(["delete", "toggle"]); // declare the events you emit
function onDelete() {
emit("delete", props.todo.id); // emit an event WITH a payload
}
</script>
<template>
<li>
{{ todo.text }}
<button @click="onDelete">Delete</button>
<button @click="emit('toggle', todo.id)">Toggle</button>
</li>
</template>
