ရိုးရိုးလေး ရှင်းပြမယ်
Template Syntax and Directives ကို ရိုးရိုးလေးနားလည်မယ်
Template ထဲတွင် {{ value }} က text interpolation ဖြစ်သည်။ HTML attribute များကို reactive value နှင့်ချိတ်ရန် v-bind သို့မဟုတ် အတိုကောက် : ကိုသုံးသည်။ User input ကို v-html ဖြင့်တိုက်ရိုက် render မလုပ်သင့်ပါ။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Attribute ထဲတွင် {{ }} သုံးခြင်း
ဖြစ်လေ့ရှိတဲ့အမှား
မယုံကြည်ရသော user input ကို v-html ဖြင့် render လုပ်ခြင်း
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Interpolation, v-bind နှင့် v-html အပါအဝင် Vue template syntax နှင့် directive အခြေခံများကို လေ့လာမည်။
- Props / event
- Component + template
- Rendered Vue UI
{{ }} interpolation သုံးရန်
အဓိက Syntax / Pattern
<script setup>
const profile = {
name: 'Su Su',
avatar: '/avatar.png',
active: true
}
</script>
<template>
<h2>{{ profile.name }}</h2>
<img :src="profile.avatar" :alt="profile.name">
<p :class="{ online: profile.active }">Online</p>
</template>Interpolation, v-bind နှင့် v-html အပါအဝင် Vue template syntax နှင့် directive အခြေခံများကို လေ့လာမည်။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Props / event
<script setup>Template ထဲတွင် {{ value }} က text interpolation ဖြစ်သည်။ HTML attribute များကို reactive value နှင့်ချိတ်ရန် v-bind သို့မဟုတ် အတိုကောက် : ကိုသုံးသည်။ User input ကို v-html ဖြင့်တိုက်ရိုက် render မလုပ်သင့်ပါ။
- Component + template
</script>Interpolation, v-bind နှင့် v-html အပါအဝင် Vue template syntax နှင့် directive အခြေခံများကို လေ့လာမည်။
- Rendered Vue UI
</template>Template Syntax and Directives ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
- Props / event
- Component + template
- Rendered Vue UI
Success
{{ }} interpolation သုံးရန်
Failure
Attribute ထဲတွင် {{ }} သုံးခြင်း
ရိုးရိုးလေး ရှင်းပြမယ်
Template ထဲတွင် {{ value }} က text interpolation ဖြစ်သည်။ HTML attribute များကို reactive value နှင့်ချိတ်ရန် v-bind သို့မဟုတ် အတိုကောက် : ကိုသုံးသည်။ User input ကို v-html ဖြင့်တိုက်ရိုက် render မလုပ်သင့်ပါ။
<script setup>
const profile = {
name: 'Su Su',
avatar: '/avatar.png',
active: true
}
</script>
<template>
<h2>{{ profile.name }}</h2>
<img :src="profile.avatar" :alt="profile.name">
<p :class="{ online: profile.active }">Online</p>
</template>Su Su
[avatar image]
Onlineလက်တွေ့စမ်းကြည့်ရန်
Product object တစ်ခုဖန်တီးပြီး title, price နှင့် image src ကို template တွင်ပြပါ။
Template Syntax — Vue.js
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Template Syntax and Directives ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Product object တစ်ခုဖန်တီးပြီး title, price နှင့် image src ကို template တွင်ပြပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
<script setup>
const profile = {
name: 'Su Su',
avatar: '/avatar.png',
active: true
}
</script>
<template>
<h2>{{ profile.name }}</h2>
<img :src="profile.avatar" :alt="profile.name">
<p :class="{ online: profile.active }">Online</p>
</template>ရလဒ်: {{ }} interpolation သုံးရန်
အရိပ်အမြွက် ကြည့်ရန်
Template Syntax and Directives ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Props / event → Component + template → Rendered Vue UI
- Interpolation, v-bind နှင့် v-html အပါအဝင် Vue template syntax နှင့် directive အခြေခံများကို လေ့လာမည်။
- Attribute ထဲတွင် {{ }} သုံးခြင်း
- Template Syntax and Directives ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။
Template Syntax — Vue.js