Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
Vue 3 & Composition API 16 mins read Free Lesson

Component Props & Custom Events (defineProps / defineEmits)

Pass data down with defineProps() and emit custom events up to parent containers with defineEmits().

Component Props & Emits

<!-- ChildComponent.vue -->
<script setup>
const props = defineProps({
    title: { type: String, required: true },
    isFree: { type: Boolean, default: true }
})

const emit = defineEmits(['start-lesson'])
</script>

<template>
    <div class="lesson-item">
        <h3>{{ title }}</h3>
        <button @click="emit('start-lesson', title)">Start</button>
    </div>
</template>