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.
- props or event
- component and template
- rendered Vue UI
Use defineProps
Core syntax or pattern
<!-- 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
- 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.
- component and template
</script>Use typed props to pass data from a parent component down to a child component.
- rendered Vue UI
</template>Apply Props and One-Way Data Flow in a small example and test normal, edge, and failure cases.
- props or event
- component and template
- 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.
<!-- 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>Vue Handbook
18,000 MMKTry 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
<!-- 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
Quick quiz 2 / 3
Quick quiz 3 / 3
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