Vue · Junior · Question 30 of 75
How does a child notify its parent?
<script setup>
const emit = defineEmits(["save"]);
function onClick() { emit("save", { id: 1 }); }
</script>
<!-- parent: <Editor @save="handleSave" /> -->- ✓Correct answer: By emitting a custom event with
defineEmitsandemit() - 2By calling a method on
this.$parent - 3By changing a global variable
Explanation
The parent listens with @save, and the payload becomes the handler argument. Unlike native DOM events, component events don't bubble.