ရိုးရိုးလေး ရှင်းပြမယ်
Conditional and List Rendering ကို ရိုးရိုးလေးနားလည်မယ်
v-if သည် condition false ဖြစ်လျှင် element ကို DOM မှဖယ်ရှားသည်။ v-show သည် CSS display ကိုသာပြောင်းလဲသောကြောင့် မကြာခဏ toggle လုပ်သည့် UI တွင်သင့်တော်သည်။ v-for list တိုင်းတွင် unique :key ထည့်ပါ။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
List index ကို key အဖြစ်သုံးခြင်း
ဖြစ်လေ့ရှိတဲ့အမှား
Element တစ်ခုတည်းပေါ်တွင် v-if နှင့် v-for ကိုအတူသုံးခြင်း
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
v-if, v-show နှင့် v-for ကို အသုံးပြုပြီး condition နှင့် collection အလိုက် UI render လုပ်မည်။
- Props / event
- Component + template
- Rendered Vue UI
v-if နှင့် v-show ကိုရွေးချယ်ရန်
အဓိက Syntax / Pattern
<script setup>
const tasks = [
{ id: 1, title: 'Read Vue guide', done: true },
{ id: 2, title: 'Build a component', done: false }
]
</script>
<template>
<p v-if="tasks.length === 0">No tasks</p>
<ul v-else>
<li v-for="task in tasks" :key="task.id">
{{ task.done ? '✓' : '○' }} {{ task.title }}
</li>
</ul>
</template>v-if, v-show နှင့် v-for ကို အသုံးပြုပြီး condition နှင့် collection အလိုက် UI render လုပ်မည်။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Props / event
<script setup>v-if သည် condition false ဖြစ်လျှင် element ကို DOM မှဖယ်ရှားသည်။ v-show သည် CSS display ကိုသာပြောင်းလဲသောကြောင့် မကြာခဏ toggle လုပ်သည့် UI တွင်သင့်တော်သည်။ v-for list တိုင်းတွင် unique :key ထည့်ပါ။
- Component + template
<p v-if="tasks.length === 0">No tasks</p>v-if, v-show နှင့် v-for ကို အသုံးပြုပြီး condition နှင့် collection အလိုက် UI render လုပ်မည်။
- Rendered Vue UI
</template>Conditional and List Rendering ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
- Props / event
- Component + template
- Rendered Vue UI
Success
v-if နှင့် v-show ကိုရွေးချယ်ရန်
Failure
List index ကို key အဖြစ်သုံးခြင်း
ရိုးရိုးလေး ရှင်းပြမယ်
v-if သည် condition false ဖြစ်လျှင် element ကို DOM မှဖယ်ရှားသည်။ v-show သည် CSS display ကိုသာပြောင်းလဲသောကြောင့် မကြာခဏ toggle လုပ်သည့် UI တွင်သင့်တော်သည်။ v-for list တိုင်းတွင် unique :key ထည့်ပါ။
<script setup>
const tasks = [
{ id: 1, title: 'Read Vue guide', done: true },
{ id: 2, title: 'Build a component', done: false }
]
</script>
<template>
<p v-if="tasks.length === 0">No tasks</p>
<ul v-else>
<li v-for="task in tasks" :key="task.id">
{{ task.done ? '✓' : '○' }} {{ task.title }}
</li>
</ul>
</template>✓ Read Vue guide
○ Build a componentလက်တွေ့စမ်းကြည့်ရန်
Products list ကို stock > 0 ဖြစ်သော item များသာပြပြီး unique id ကို key အဖြစ်သုံးပါ။
List Rendering — Vue.js
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Conditional and List Rendering ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Products list ကို stock > 0 ဖြစ်သော item များသာပြပြီး unique id ကို key အဖြစ်သုံးပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
<script setup>
const tasks = [
{ id: 1, title: 'Read Vue guide', done: true },
{ id: 2, title: 'Build a component', done: false }
]
</script>
<template>
<p v-if="tasks.length === 0">No tasks</p>
<ul v-else>
<li v-for="task in tasks" :key="task.id">
{{ task.done ? '✓' : '○' }} {{ task.title }}
</li>
</ul>
</template>ရလဒ်: v-if နှင့် v-show ကိုရွေးချယ်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Conditional and List Rendering ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Props / event → Component + template → Rendered Vue UI
- v-if, v-show နှင့် v-for ကို အသုံးပြုပြီး condition နှင့် collection အလိုက် UI render လုပ်မည်။
- List index ကို key အဖြစ်သုံးခြင်း
- Conditional and List Rendering ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
List Rendering — Vue.js