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

Slots and Flexible Components

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

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

  • Slot content ပေးရန်
  • Named slot သုံးရန်
  • Scoped slot data လက်ခံရန်

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

Slots and Flexible Components ကို ရိုးရိုးလေးနားလည်မယ်

Props က data ပို့သကဲ့သို့ slots က template content ပို့သည်။ Card, modal နှင့် layout ကဲ့သို့ wrapper component များတွင် slot သင့်တော်သည်။ Named slot ဖြင့် header/body/footer ကိုခွဲနိုင်ပြီး scoped slot ဖြင့် child data ကို parent template သို့ပေးနိုင်သည်။

Problem → Why → Solution

ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ

Slot နှင့် prop တို့၏ ရည်ရွယ်ချက်ကိုရောထွေးခြင်း

ဖြစ်လေ့ရှိတဲ့အမှား

Fallback content မထည့်သဖြင့် empty UI ဖြစ်ခြင်း

Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်

Default, named နှင့် scoped slots ဖြင့် reusable layout component များတည်ဆောက်မည်။

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

Slot content ပေးရန်

အဓိက Syntax / Pattern

vue
<!-- BaseCard.vue -->
<template>
  <article class="card">
    <header><slot name="title">Untitled</slot></header>
    <div><slot /></div>
    <footer><slot name="actions" /></footer>
  </article>
</template>

<!-- usage -->
<BaseCard>
  <template #title>Vue Course</template>
  <p>20 practical lessons</p>
  <template #actions><button>Start</button></template>
</BaseCard>

Default, named နှင့် scoped slots ဖြင့် reusable layout component များတည်ဆောက်မည်။

Code ကို အဆင့်လိုက်ဖတ်မယ်

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

    Props က data ပို့သကဲ့သို့ slots က template content ပို့သည်။ Card, modal နှင့် layout ကဲ့သို့ wrapper component များတွင် slot သင့်တော်သည်။ Named slot ဖြင့် header/body/footer ကိုခွဲနိုင်ပြီး scoped slot ဖြင့် child data ကို parent template သို့ပေးနိုင်သည်။

  2. Component + template</template>

    Default, named နှင့် scoped slots ဖြင့် reusable layout component များတည်ဆောက်မည်။

  3. Rendered Vue UI</BaseCard>

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

Execution Flow
  1. Props / event
  2. Component + template
  3. Rendered Vue UI

Success

Slot content ပေးရန်

Failure

Slot နှင့် prop တို့၏ ရည်ရွယ်ချက်ကိုရောထွေးခြင်း

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

Props က data ပို့သကဲ့သို့ slots က template content ပို့သည်။ Card, modal နှင့် layout ကဲ့သို့ wrapper component များတွင် slot သင့်တော်သည်။ Named slot ဖြင့် header/body/footer ကိုခွဲနိုင်ပြီး scoped slot ဖြင့် child data ကို parent template သို့ပေးနိုင်သည်။

vue
<!-- BaseCard.vue -->
<template>
  <article class="card">
    <header><slot name="title">Untitled</slot></header>
    <div><slot /></div>
    <footer><slot name="actions" /></footer>
  </article>
</template>

<!-- usage -->
<BaseCard>
  <template #title>Vue Course</template>
  <p>20 practical lessons</p>
  <template #actions><button>Start</button></template>
</BaseCard>
You should see
Vue Course
20 practical lessons
[Start]

လက်တွေ့စမ်းကြည့်ရန်

Header, content နှင့် footer named slots ပါသော BaseModal component တစ်ခုရေးပါ။

Slots — Vue.js

Real-world usage

လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ

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

Mini challenge

ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ

Header, content နှင့် footer named slots ပါသော BaseModal component တစ်ခုရေးပါ။

  • Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
  • Normal input နဲ့ edge case စမ်းပါ
  • Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
vue
<!-- BaseCard.vue -->
<template>
  <article class="card">
    <header><slot name="title">Untitled</slot></header>
    <div><slot /></div>
    <footer><slot name="actions" /></footer>
  </article>
</template>

<!-- usage -->
<BaseCard>
  <template #title>Vue Course</template>
  <p>20 practical lessons</p>
  <template #actions><button>Start</button></template>
</BaseCard>

ရလဒ်: Slot content ပေးရန်

အရိပ်အမြွက် ကြည့်ရန်

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

Quick Quiz 1 / 3

Slots and Flexible Components ရဲ့ အဓိကသဘောတရားက ဘာလဲ။

Quick Quiz 2 / 3

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

Quick Quiz 3 / 3

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

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

  • Props / event → Component + template → Rendered Vue UI
  • Default, named နှင့် scoped slots ဖြင့် reusable layout component များတည်ဆောက်မည်။
  • Slot နှင့် prop တို့၏ ရည်ရွယ်ချက်ကိုရောထွေးခြင်း
  • Slots and Flexible Components ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။

Slots — Vue.js

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

  • Slot နှင့် prop တို့၏ ရည်ရွယ်ချက်ကိုရောထွေးခြင်း
  • Fallback content မထည့်သဖြင့် empty UI ဖြစ်ခြင်း

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

Header, content နှင့် footer named slots ပါသော BaseModal component တစ်ခုရေးပါ။

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: Vue Course 20 practical lessons [Start]

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

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

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

Slots and Flexible Components | Thuta Learning