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

Template Syntax and Directives

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

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

  • {{ }} interpolation သုံးရန်
  • v-bind ဖြင့် attribute ချိတ်ရန်
  • Directive syntax ကိုဖတ်နိုင်ရန်

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

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 အခြေခံများကို လေ့လာမည်။

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

{{ }} interpolation သုံးရန်

အဓိက Syntax / Pattern

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

  1. Props / event<script setup>

    Template ထဲတွင် {{ value }} က text interpolation ဖြစ်သည်။ HTML attribute များကို reactive value နှင့်ချိတ်ရန် v-bind သို့မဟုတ် အတိုကောက် : ကိုသုံးသည်။ User input ကို v-html ဖြင့်တိုက်ရိုက် render မလုပ်သင့်ပါ။

  2. Component + template</script>

    Interpolation, v-bind နှင့် v-html အပါအဝင် Vue template syntax နှင့် directive အခြေခံများကို လေ့လာမည်။

  3. Rendered Vue UI</template>

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

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

Success

{{ }} interpolation သုံးရန်

Failure

Attribute ထဲတွင် {{ }} သုံးခြင်း

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

Template ထဲတွင် {{ value }} က text interpolation ဖြစ်သည်။ HTML attribute များကို reactive value နှင့်ချိတ်ရန် v-bind သို့မဟုတ် အတိုကောက် : ကိုသုံးသည်။ User input ကို v-html ဖြင့်တိုက်ရိုက် render မလုပ်သင့်ပါ။

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

Template Syntax and Directives ရဲ့ အဓိကသဘောတရားက ဘာလဲ။

Quick Quiz 2 / 3

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

Quick Quiz 3 / 3

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

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

  • 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

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

  • Attribute ထဲတွင် {{ }} သုံးခြင်း
  • မယုံကြည်ရသော user input ကို v-html ဖြင့် render လုပ်ခြင်း

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

Product object တစ်ခုဖန်တီးပြီး title, price နှင့် image src ကို template တွင်ပြပါ။

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: Su Su [avatar image] Online

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

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

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

Template Syntax and Directives | Thuta Learning