ရိုးရိုးလေး ရှင်းပြမယ်
Component Basics ကို ရိုးရိုးလေးနားလည်မယ်
Vue component တစ်ခုတွင် <script setup>, <template> နှင့် optional <style scoped> ပါနိုင်သည်။ Component ကို feature သို့မဟုတ် responsibility တစ်ခုစီအလိုက်သေးငယ်စွာခွဲပါ။ <script setup> တွင် import လုပ်ထားသော component ကို template မှ တိုက်ရိုက်သုံးနိုင်သည်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Component တစ်ခုထဲတွင် feature အားလုံးထည့်ခြင်း
ဖြစ်လေ့ရှိတဲ့အမှား
SFC တွင် component import မလုပ်ဘဲ tag သုံးခြင်း
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Single-File Component များဖြင့် UI ကို သီးခြားပြန်လည်အသုံးပြုနိုင်သော အပိုင်းများအဖြစ် ခွဲမည်။
- Props / event
- Component + template
- Rendered Vue UI
Vue SFC structure ကိုနားလည်ရန်
အဓိက Syntax / Pattern
<!-- CounterButton.vue -->
<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>
<template>
<button @click="count++">Clicked {{ count }} times</button>
</template>
<style scoped>
button { padding: .75rem 1rem; }
</style>Single-File Component များဖြင့် UI ကို သီးခြားပြန်လည်အသုံးပြုနိုင်သော အပိုင်းများအဖြစ် ခွဲမည်။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Props / event
<!-- CounterButton.vue -->Vue component တစ်ခုတွင် <script setup>, <template> နှင့် optional <style scoped> ပါနိုင်သည်။ Component ကို feature သို့မဟုတ် responsibility တစ်ခုစီအလိုက်သေးငယ်စွာခွဲပါ။ <script setup> တွင် import လုပ်ထားသော component ကို template မှ တိုက်ရိုက်သုံးနိုင်သည်။
- Component + template
<template>Single-File Component များဖြင့် UI ကို သီးခြားပြန်လည်အသုံးပြုနိုင်သော အပိုင်းများအဖြစ် ခွဲမည်။
- Rendered Vue UI
</style>Component Basics ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
- Props / event
- Component + template
- Rendered Vue UI
Success
Vue SFC structure ကိုနားလည်ရန်
Failure
Component တစ်ခုထဲတွင် feature အားလုံးထည့်ခြင်း
ရိုးရိုးလေး ရှင်းပြမယ်
Vue component တစ်ခုတွင် <script setup>, <template> နှင့် optional <style scoped> ပါနိုင်သည်။ Component ကို feature သို့မဟုတ် responsibility တစ်ခုစီအလိုက်သေးငယ်စွာခွဲပါ။ <script setup> တွင် import လုပ်ထားသော component ကို template မှ တိုက်ရိုက်သုံးနိုင်သည်။
<!-- CounterButton.vue -->
<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>
<template>
<button @click="count++">Clicked {{ count }} times</button>
</template>
<style scoped>
button { padding: .75rem 1rem; }
</style>Clicked 0 timesလက်တွေ့စမ်းကြည့်ရန်
AvatarCard.vue component တစ်ခုဖန်တီးပြီး App.vue ထဲတွင် သုံးကြိမ်ပြန်လည်အသုံးပြုပါ။
Components Basics — Vue.js
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Component Basics ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
AvatarCard.vue component တစ်ခုဖန်တီးပြီး App.vue ထဲတွင် သုံးကြိမ်ပြန်လည်အသုံးပြုပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
<!-- CounterButton.vue -->
<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>
<template>
<button @click="count++">Clicked {{ count }} times</button>
</template>
<style scoped>
button { padding: .75rem 1rem; }
</style>ရလဒ်: Vue SFC structure ကိုနားလည်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Component Basics ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Props / event → Component + template → Rendered Vue UI
- Single-File Component များဖြင့် UI ကို သီးခြားပြန်လည်အသုံးပြုနိုင်သော အပိုင်းများအဖြစ် ခွဲမည်။
- Component တစ်ခုထဲတွင် feature အားလုံးထည့်ခြင်း
- Component Basics ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
Components Basics — Vue.js