- Props pass data from parent to child:
props: ["title"], used as<course-card title="Vue">. - Bind dynamic values with
:title="course.name". - Emits send events from child to parent:
this.$emit("select", id), listened to with@select="handler".
Vue Props & Emits
Pass data down and send events up.
✍️ 3 exercises + code challenge in this lessonKey Takeaways: Vue Props & Emits
Mastering Vue Props & Emits helps you write clean and reliable Vue.js code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
Vue Props & Emits Code Example
Vue.js<script src="https://unpkg.com/vue@3.5.12/dist/vue.global.prod.js"></script>
<div id="app">
<course-card v-for="c in courses" :key="c" :title="c" @enrol="chosen = $event"></course-card>
<p>Chosen: {{ chosen || 'none' }}</p>
</div>
<script>
const app = Vue.createApp({
data() { return { courses: ["Vue", "React", "Python"], chosen: null }; }
});
app.component("course-card", {
props: ["title"],
emits: ["enrol"],
template: `<div style="border:1px solid #ccc;padding:8px;margin:4px 0">
{{ title }} <button @click="$emit('enrol', title)">Enrol</button>
</div>`
});
app.mount("#app");
</script>
Vue Props & Emits Practice Exercises
Check what you learned in “Vue Props & Emits”.
Declare the props a component accepts.
: ["title"]
How does a child component send data to its parent?
Give the "greet-user" component a name prop and render "Hi, {{ name }}" in a <p>. Use it as <greet-user name="Ali">.
Free sign-in required · Google login available
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services