ရိုးရိုးလေး ရှင်းပြမယ်
Props and One-Way Data Flow ကို ရိုးရိုးလေးနားလည်မယ်
Props သည် parent မှ child သို့ one-way data flow ဖြစ်သည်။ Child က prop ကိုတိုက်ရိုက်မပြောင်းဘဲ ပြောင်းလဲလိုပါက event emit လုပ်ရမည်။ Type, required နှင့် default validation များဖြင့် component contract ကိုရှင်းလင်းစေပါ။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Child ထဲမှ prop ကိုတိုက်ရိုက် mutate လုပ်ခြင်း
ဖြစ်လေ့ရှိတဲ့အမှား
Number prop ကို :price မသုံးဘဲ string အဖြစ်ပို့ခြင်း
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Parent component မှ child component သို့ data ပေးပို့ရန် typed props ကိုအသုံးပြုမည်။
- Props / event
- Component + template
- Rendered Vue UI
defineProps သုံးရန်
အဓိက Syntax / 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>Parent component မှ child component သို့ data ပေးပို့ရန် typed props ကိုအသုံးပြုမည်။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Props / event
<!-- ProductCard.vue -->Props သည် parent မှ child သို့ one-way data flow ဖြစ်သည်။ Child က prop ကိုတိုက်ရိုက်မပြောင်းဘဲ ပြောင်းလဲလိုပါက event emit လုပ်ရမည်။ Type, required နှင့် default validation များဖြင့် component contract ကိုရှင်းလင်းစေပါ။
- Component + template
</script>Parent component မှ child component သို့ data ပေးပို့ရန် typed props ကိုအသုံးပြုမည်။
- Rendered Vue UI
</template>Props and One-Way Data Flow ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
- Props / event
- Component + template
- Rendered Vue UI
Success
defineProps သုံးရန်
Failure
Child ထဲမှ prop ကိုတိုက်ရိုက် mutate လုပ်ခြင်း
ရိုးရိုးလေး ရှင်းပြမယ်
Props သည် parent မှ child သို့ one-way data flow ဖြစ်သည်။ Child က prop ကိုတိုက်ရိုက်မပြောင်းဘဲ ပြောင်းလဲလိုပါက event emit လုပ်ရမည်။ Type, required နှင့် default validation များဖြင့် component contract ကိုရှင်းလင်းစေပါ။
<!-- 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 MMKလက်တွေ့စမ်းကြည့်ရန်
UserBadge component ကို name, role နှင့် online Boolean props များဖြင့် တည်ဆောက်ပါ။
Props — Vue.js
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Props and One-Way Data Flow ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
UserBadge component ကို name, role နှင့် online Boolean props များဖြင့် တည်ဆောက်ပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
<!-- 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>ရလဒ်: defineProps သုံးရန်
အရိပ်အမြွက် ကြည့်ရန်
Props and One-Way Data Flow ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Props / event → Component + template → Rendered Vue UI
- Parent component မှ child component သို့ data ပေးပို့ရန် typed props ကိုအသုံးပြုမည်။
- Child ထဲမှ prop ကိုတိုက်ရိုက် mutate လုပ်ခြင်း
- Props and One-Way Data Flow ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
Props — Vue.js