ရိုးရိုးလေး ရှင်းပြမယ်
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 များတည်ဆောက်မည်။
- Props / event
- Component + template
- Rendered Vue UI
Slot content ပေးရန်
အဓိက Syntax / Pattern
<!-- 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 ကို အဆင့်လိုက်ဖတ်မယ်
- 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 သို့ပေးနိုင်သည်။
- Component + template
</template>Default, named နှင့် scoped slots ဖြင့် reusable layout component များတည်ဆောက်မည်။
- Rendered Vue UI
</BaseCard>Slots and Flexible Components ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
- Props / event
- Component + template
- 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 သို့ပေးနိုင်သည်။
<!-- 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>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 ကိုခန့်မှန်းပါ
<!-- 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
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- 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