javascript / beginner
Snippet
Declaring Custom Events with defineEmits
To send data from a child component back to its parent, you must declare the events the component can fire using defineEmits.
snippet.js
1
2
3
4
5
6
7
<script setup>const emit = defineEmits(['close', 'submit']);function handleAction() {emit('submit', { id: 1 });}</script>
vue
Breakdown
1
const emit = defineEmits(['close', 'submit']);
Defines the specific events this component is allowed to trigger.
2
emit('submit', { id: 1 });
Triggers the 'submit' event and passes an object as a payload.