Thuta Learning
Vue.js
IntermediateWeb Developmentအခြေခံ

Component Basics

Vue.jsသင်ခန်းစာ 1020 မိနစ်

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Vue SFC structure ကိုနားလည်ရန်
  • Child component import နှင့်အသုံးပြုရန်

ရိုးရိုးလေး ရှင်းပြမယ်

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 ကို သီးခြားပြန်လည်အသုံးပြုနိုင်သော အပိုင်းများအဖြစ် ခွဲမည်။

Mental Model
  1. Props / event
  2. Component + template
  3. Rendered Vue UI

Vue SFC structure ကိုနားလည်ရန်

အဓိက Syntax / Pattern

vue
<!-- 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 ကို အဆင့်လိုက်ဖတ်မယ်

  1. Props / event<!-- CounterButton.vue -->

    Vue component တစ်ခုတွင် <script setup>, <template> နှင့် optional <style scoped> ပါနိုင်သည်။ Component ကို feature သို့မဟုတ် responsibility တစ်ခုစီအလိုက်သေးငယ်စွာခွဲပါ။ <script setup> တွင် import လုပ်ထားသော component ကို template မှ တိုက်ရိုက်သုံးနိုင်သည်။

  2. Component + template<template>

    Single-File Component များဖြင့် UI ကို သီးခြားပြန်လည်အသုံးပြုနိုင်သော အပိုင်းများအဖြစ် ခွဲမည်။

  3. Rendered Vue UI</style>

    Component Basics ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။

Execution Flow
  1. Props / event
  2. Component + template
  3. 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 မှ တိုက်ရိုက်သုံးနိုင်သည်။

vue
<!-- 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>
You should see
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 ကိုခန့်မှန်းပါ
vue
<!-- 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

Component Basics ရဲ့ အဓိကသဘောတရားက ဘာလဲ။

Quick Quiz 2 / 3

ဘယ်အမှားကို အရင်ဆုံးရှောင်သင့်လဲ။

Quick Quiz 3 / 3

Real project မှာ ဘယ်လိုအသုံးချသင့်လဲ။

ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ

  • Props / event → Component + template → Rendered Vue UI
  • Single-File Component များဖြင့် UI ကို သီးခြားပြန်လည်အသုံးပြုနိုင်သော အပိုင်းများအဖြစ် ခွဲမည်။
  • Component တစ်ခုထဲတွင် feature အားလုံးထည့်ခြင်း
  • Component Basics ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။

Components Basics — Vue.js

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Component တစ်ခုထဲတွင် feature အားလုံးထည့်ခြင်း
  • SFC တွင် component import မလုပ်ဘဲ tag သုံးခြင်း

လေ့ကျင့်ခန်း

AvatarCard.vue component တစ်ခုဖန်တီးပြီး App.vue ထဲတွင် သုံးကြိမ်ပြန်လည်အသုံးပြုပါ။

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: Clicked 0 times

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။