ஒரு குழந்தை தனது பெற்றோர்களுக்கு மேலே நிகழ்வுகளை வெளியிட்டு தொடர்புகொள்கிறது. பெற்றோர் அவற்றை @event-name மூலம் கேட்கிறார்கள். இது Vue இன் ஒரு வழி தரவு ஓட்டத்தை முடிக்கிறது: props கீழே, நிகழ்வுகள் மேலே.
குழந்தை கூறிலிருந்து வெளியிடுதல்
<!-- 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>
