Vue Props & Emits

Pass data down and send events up.

✍️ 3 exercises + code challenge in this lesson
  • 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".

Key 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>
Free sign-in required · Google login available

Vue Props & Emits Practice Exercises

Check what you learned in “Vue Props & Emits”.

/ 3 solved
Fill in the blank

Declare the props a component accepts.

: ["title"]
✓ Correct! Not quite. Try again.
Multiple choice

How does a child component send data to its parent?

✓ Correct! Not quite. Try again.
Code challenge

Give the "greet-user" component a name prop and render "Hi, {{ name }}" in a <p>. Use it as <greet-user name="Ali">.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

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