Thuta Learning
Vue.js
IntermediateWeb DevelopmentBeginner

Props and One-Way Data Flow

Vue.jsLesson 1120 min

What you'll walk away with

  • Use defineProps
  • Bind dynamic props
  • Understand why you shouldn't mutate props

Explain it simply

Props and One-Way Data Flow, in plain language

Props flow one way, from parent to child. The child should never modify a prop directly — if it needs to change something, it should emit an event instead. Use type, required, and default validation to make the component's contract clear.

Problem → Why → Solution

The problem — why this concept matters

Mutating a prop directly inside the child

A common mistake

Passing a number prop as a string instead of using :price

Core concept — understand how it works

Use typed props to pass data from a parent component down to a child component.

Mental model
  1. props or event
  2. component and template
  3. rendered Vue UI

Use defineProps

Core syntax or pattern

vue
<!-- ProductCard.vue -->
<script setup>
const props = defineProps({
  title: { type: String, required: true },
  price: { type: Number, default: 0 }
})
</script>

<template>
  <article>
    <h3>{{ props.title }}</h3>
    <p>{{ props.price.toLocaleString() }} MMK</p>
  </article>
</template>

Use typed props to pass data from a parent component down to a child component.

Read the code step by step

  1. props or event<!-- ProductCard.vue -->

    Props flow one way, from parent to child. The child should never modify a prop directly — if it needs to change something, it should emit an event instead. Use type, required, and default validation to make the component's contract clear.

  2. component and template</script>

    Use typed props to pass data from a parent component down to a child component.

  3. rendered Vue UI</template>

    Apply Props and One-Way Data Flow in a small example and test normal, edge, and failure cases.

Execution flow
  1. props or event
  2. component and template
  3. rendered Vue UI

Success

Use defineProps

Failure

Mutating a prop directly inside the child

Let's break it down simply

Props flow one way, from parent to child. The child should never modify a prop directly — if it needs to change something, it should emit an event instead. Use type, required, and default validation to make the component's contract clear.

vue
<!-- ProductCard.vue -->
<script setup>
const props = defineProps({
  title: { type: String, required: true },
  price: { type: Number, default: 0 }
})
</script>

<template>
  <article>
    <h3>{{ props.title }}</h3>
    <p>{{ props.price.toLocaleString() }} MMK</p>
  </article>
</template>
You should see
Vue Handbook
18,000 MMK

Try it yourself

Build a UserBadge component with name, role, and online Boolean props.

Props — Vue.js

Real-world usage

How to apply it in a real project

Apply Props and One-Way Data Flow in a small example and test normal, edge, and failure cases.

Mini challenge

Build it yourself

Build a UserBadge component with name, role, and online Boolean props.

  • Rebuild the example without copying it
  • Test a normal input and an edge case
  • Predict the compiler or output result before running it
vue
<!-- ProductCard.vue -->
<script setup>
const props = defineProps({
  title: { type: String, required: true },
  price: { type: Number, default: 0 }
})
</script>

<template>
  <article>
    <h3>{{ props.title }}</h3>
    <p>{{ props.price.toLocaleString() }} MMK</p>
  </article>
</template>

Expected: Use defineProps

Show hint

Apply Props and One-Way Data Flow in a small example and test normal, edge, and failure cases.

Quick quiz 1 / 3

What best describes the core idea of Props and One-Way Data Flow?

Quick quiz 2 / 3

Which mistake should you avoid first?

Quick quiz 3 / 3

How should this be applied in a real project?

What to remember

  • props or event → component and template → rendered Vue UI
  • Use typed props to pass data from a parent component down to a child component.
  • Mutating a prop directly inside the child
  • Apply Props and One-Way Data Flow in a small example and test normal, edge, and failure cases.

Props — Vue.js

Easy traps

  • Mutating a prop directly inside the child
  • Passing a number prop as a string instead of using :price

Exercise

Build a UserBadge component with name, role, and online Boolean props.

You'll know it worked when: Vue Handbook 18,000 MMK

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.