Vue 3 + Quasar မြန်မာ သင်ခန်းစာ
Vue 3 · Quasar · Composition API

Vue နဲ့ Quasar ကို မြန်မာလို
App ဆောက်တဲ့အထိ

JavaScript အခြေခံ ရှိပြီးသားဆိုရင် Vue က မျက်နှာပြင်ကို ရှင်းရှင်း ရေးနိုင်တဲ့ နည်းလမ်း ဖြစ်တယ်။ Reactivity၊ component၊ router၊ Pinia နဲ့ Quasar layout/components ကို အခန်း ၁၈ ခန်း နဲ့ မေးခွန်း ၂၂ ပုဒ် ထည့်ထားတယ်။

အခန်း ၁၈ ခန်း Vue 3 Composition API Quasar CLI Copy · Dark / Light
01

Vue အခြေခံ

Template · Reactivity · Event · v-if/v-for

02

App တည်ဆောက်မှု

Component · Router · Pinia · Fetch

03

Quasar နဲ့ ပို့

Components · Layout · Build · PWA

ဖတ်ရှုရန် မှတ်ချက်

ဒီစာမျက်နှာက ဖတ်ရှုရန် သင်ခန်းစာပါ။ Vue/Quasar က build tool လိုတာမို့ ကုဒ်တွေကို ဒီစာမျက်နှာမှာ run မထားပါဘူး — ကုဒ်တိုင်းရဲ့ အောက်မှာ Expected Output ကို ပြထားတယ်။ လက်တွေ့ စမ်းချင်ရင် Node.js ၂၀+ install ပြီး ကိုယ်ပိုင် project မှာ run ပါ။

အခန်း 01 · Vue အခြေခံ

Vue ဆိုတာ ဘာလဲ

Vue က website ရဲ့ မျက်နှာပြင်ကို “ဒေတာ ပြောင်းရင် မျက်နှာပြင် အလိုအလျောက် ပြောင်း” ဆိုတဲ့ ပုံစံနဲ့ ရေးနိုင်တဲ့ JavaScript framework ပါ။ ဒေတာကို ကိုင်တွယ်တဲ့ ကုဒ်နဲ့ မျက်နှာပြင် ကုဒ်ကို ရှင်းရှင်း ခွဲထားနိုင်တယ်။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • Vue က ဘာကို ဖြေရှင်းပေးလဲ
  • Declarative rendering ဆိုတာ ဘာလဲ
  • SPA နဲ့ Component ရဲ့ အယူအဆ
  • Vanilla JavaScript နဲ့ ကွာခြားချက်

၁။ ဘာကြောင့် Vue သုံးလဲ

Vanilla JS မှာ ဒေတာ ပြောင်းတိုင်း DOM ကို ကိုယ်တိုင် ရှာပြီး ပြင်ရတယ် — document.querySelector("#total").textContent = total။ Element များလာရင် ရှုပ်လာတယ်။ Vue မှာ ဒေတာ ပြောင်းလိုက်ရုံနဲ့ မျက်နှာပြင်က အလိုအလျောက် ပြောင်းတယ်။ ဒါကို reactivity လို့ ခေါ်တယ်။

အချက်Vanilla JSVue
မျက်နှာပြင် ပြင်ဆင်DOM ကို ကိုယ်တိုင် ရှာ/ပြင်ဒေတာ ပြောင်းရုံ
ကုဒ် ဖွဲ့စည်းပုံလုပ်ငန်း ကြီးလာရင် ရှုပ်Component အလိုက် ခွဲ
အခြေအနေ (state)variable တွေ ကွဲပြားတစ်နေရာတည်း စုစည်း

၂။ အသေးဆုံး Vue ဥပမာ

index.html HTML
<div id="app">{{ message }}</div>

<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
  Vue.createApp({
    data() {
      return { message: "မင်္ဂလာပါ Vue!" };
    }
  }).mount("#app");
</script>
Expected Output — browser မှာ ဖွင့်ရင်
မင်္ဂလာပါ Vue!

{{ message }} က template ထဲမှာ ဒေတာကို ထည့်တဲ့ နည်း။ message ကို ပြောင်းလိုက်ရင် မျက်နှာပြင်က ချက်ချင်း ပြောင်းတယ်။ ဒီဥပမာက လေ့လာဖို့ပါ — project တကယ်ဆောက်ရင် Vite/Quasar သုံးတယ် (အခန်း ၂၊ ၁၃)။

၃။ SPA နဲ့ Component

  • SPA (Single Page Application) — မျက်နှာပြင် တစ်ခုတည်းမှာ route တွေ ပြောင်းတာ၊ page မလှန်ဘဲ ချက်ချင်း ပြည့်တယ်။
  • Component — မျက်နှာပြင် အပိုင်းတစ်ခုစီ (navbar၊ ပစ္စည်းကတ်၊ ဇယား) ကို သီးခြား ဖိုင်နဲ့ ရေးတယ်။ ပြန်သုံးလို့ရ၊ စမ်းရ လွယ်တယ်။
  • Composition API — Vue 3 ရဲ့ ဒေတာ/လုပ်ဆောင်ချက် စုစည်းရေးတဲ့ ပုံစံ၊ <script setup> နဲ့ ရေးတာ အသုံးများတယ်။
ဥပမာ — LEGO တုံး

Website တစ်ခုကို LEGO တုံးတွေ တည်ဆောက်သလို မြင်ပါ။ Component တစ်ခုက တုံးတစ်တုံး။ ပစ္စည်းကတ် တုံးကို နေရာ ၁၀ နေရာမှာ သုံးချင်ရင် တစ်ခါရေးပြီး ၁၀ ခါ ခေါ်ရုံပါပဲ။

အခန်း 02 · စတင်တည်ဆောက်ခြင်း

Setup (Vite / CDN)

Vue project ကို နည်း ၂ မျိုးနဲ့ စနိုင်တယ် — လေ့လာဖို့ CDN (script တစ်ကြောင်း)၊ တကယ့် project အတွက် Vite။ တကယ့် project မှာ Vite ကို သုံးပါ။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • Node.js လိုအပ်ချက်
  • create-vue နဲ့ project ဖန်တီးပုံ
  • Project ဖွဲ့စည်းပုံ
  • Dev server နဲ့ build

၁။ Project ဖန်တီးခြင်း

terminal BASH
npm create vue@latest shop-app
cd shop-app
npm install
npm run dev
Expected Output — npm run dev
VITE v6.x  ready in 512 ms
➜  Local:   http://localhost:5173/
➜  Network: use --host to expose

Node.js ၂၀+ လိုတယ်။ npm create vue@latest က အခြေခံ project တည်ဆောက်ပေးတယ်။ မေးခွန်း တွေ့ရင် TypeScript/Router/Pinia ကို ကိုယ်လိုတာ ရွေးနိုင်တယ်။ စလေ့လာသူအတွက် Router + Pinia ကို ရွေးထားတာ ကောင်းတယ်။

၂။ Project ဖွဲ့စည်းပုံ

နေရာဘာရှိလဲ
src/main.jsApp စတင် mount လုပ်တဲ့ နေရာ
src/App.vueအပေါ်ဆုံး component
src/components/ပြန်သုံးမယ့် component ငယ်များ
src/views/Route တစ်ခုချင်းစီရဲ့ မျက်နှာပြင်
src/stores/Pinia store (အခန်း ၁၀)
vite.config.jsBuild/dev config

၃။ Single File Component (SFC)

src/App.vue VUE
<script setup>
import { ref } from "vue";
const shopName = ref("NCT လျှပ်စစ်ပစ္စည်း");
</script>

<template>
  <h1>{{ shopName }}</h1>
</template>

<style scoped>
h1 { color: #42b883; }
</style>
Expected Output — browser မှာ ပြမယ်
NCT လျှပ်စစ်ပစ္စည်း   (အစိမ်းရောင် ခေါင်းစဉ်)

ဖိုင် တစ်ခုထဲမှာ template (မျက်နှာပြင်)၊ script (ဒေတာ/လုပ်ဆောင်ချက်)၊ style (scoped ဆိုရင် ဒီ component မှာပဲ သက်ရောက်) သုံးပိုင်း ပါတယ်။

CDN ကို ဘယ်အခါ သုံးမလဲ

HTML ဖိုင် တစ်ခုထဲမှာ Vue ကို စမ်းကြည့်ချင်ရင် CDN က လွယ်တယ်။ ဒါပေမယ့် route၊ component များတဲ့ project အတွက် Vite/Quasar က ပိုသင့်တယ် — hot reload၊ build optimization စတာတွေ ပါတယ်။

အခန်း 03 · Template

Template နဲ့ Data Binding

Vue template က HTML နဲ့ တူတယ် — ထပ်ဆောင်း အနေနဲ့ {{ }} နဲ့ directive (v-bind, v-if စတာတွေ) ပါတယ်။ ဒီခန်းမှာ ဒေတာ ပြခြင်းနဲ့ attribute ချိတ်ခြင်းကို လေ့လာမယ်။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • Interpolation {{ }}
  • v-bind နဲ့ attribute ချိတ်ခြင်း
  • Dynamic class နဲ့ style
  • Template ထဲမှာ ခေါ်လို့ရတဲ့ expression

၁။ ဒေတာ ပြခြင်း

ProductCard.vue VUE
<script setup>
import { ref } from "vue";
const name = ref("မီးသီး 9W");
const price = ref(1500);
const qty = ref(3);
</script>

<template>
  <h2>{{ name }}</h2>
  <p>ဈေး: {{ price.toLocaleString() }} ကျပ်</p>
  <p>စုစုပေါင်း: {{ price * qty }} ကျပ်</p>
</template>
Expected Output — browser မှာ ပြမယ်
မီးသီး 9W
ဈေး: 1,500 ကျပ်
စုစုပေါင်း: 4500 ကျပ်

{{ }} ထဲမှာ expression ရေးလို့ရတယ် — price * qty၊ name.toUpperCase()။ ဒါပေမယ့် if၊ assignment (x = 1) လို statement မရဘူး။ ရှုပ်တဲ့ တွက်ချက်မှုကို computed မှာ ရေးပါ (အခန်း ၄)။

၂။ v-bind — Attribute ချိတ်ခြင်း

Avatar.vue VUE
<script setup>
const imgUrl = "/img/logo.png";
const isActive = true;
const size = 48;
</script>

<template>
  <img :src="imgUrl" :width="size" alt="logo">
  <button :disabled="!isActive">မှာယူမယ်</button>
  <div :class="{ active: isActive, big: size > 40 }">အခြေအနေ</div>
</template>
Expected Output — ထွက်လာတဲ့ HTML
<img src="/img/logo.png" width="48" alt="logo">
<button disabled="">မှာယူမယ်</button>
<div class="active big">အခြေအနေ</div>

:src က v-bind:src အတိုကောက်။ :class မှာ object ပုံစံနဲ့ “ဘယ်အခြေအနေမှာ ဘယ် class” ဆိုပြီး ရေးနိုင်တယ်။ String "active" ကို static class အဖြစ် ဒီအတိုင်း ရေးလို့ရတယ်။

၃။ Template ထဲမှာ ခေါ်လို့ရတာ

ရေးလို့ရမရ
{{ a + b }}{{ if (a) {} }}
{{ ok ? "ရ" : "မရ" }}{{ x = 5 }}
{{ list.length }}{{ for (i of list) {} }}
ထောင်ချောက် — ref ကို template မှာ .value မလိုဘူး

<script setup> ထဲမှာ name.value လို့ ရေးရပေမယ့် template မှာ {{ name }} လို့ပဲ ရေးရတယ် — Vue က အလိုအလျောက် ဖွင့်ပေးတယ်။ Template မှာ name.value ရေးရင် undefined ရနိုင်တယ်။

အခန်း 04 · တုံ့ပြန်မှု

Reactivity (ref / reactive / computed)

Reactivity ဆိုတာ ဒေတာ ပြောင်းရင် မျက်နှာပြင် အလိုအလျောက် လိုက်ပြောင်းတဲ့ စနစ်ပါ။ Vue 3 မှာ ref၊ reactive နဲ့ computed က အဓိက တန်ဆာတွေပါ။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • ref နဲ့ တန်ဖိုး တစ်ခု
  • reactive နဲ့ object
  • computed ရဲ့ cache အာနိသင်
  • ဘယ်ဟာ ဘယ်အခါ သုံးမလဲ

၁။ ref

Counter.vue VUE
<script setup>
import { ref } from "vue";
const count = ref(0);

function add() {
  count.value++;   // script ထဲမှာ .value လိုတယ်
}
</script>

<template>
  <p>အရေအတွက်: {{ count }}</p>
  <button @click="add">+1</button>
</template>
Expected Output — +1 နှိပ်ပြီးနောက်
အရေအတွက်: 1

၂။ reactive

Cart.vue VUE
<script setup>
import { reactive } from "vue";
const cart = reactive({ qty: 2, price: 1500 });

function addOne() {
  cart.qty++;      // .value မလို
}
</script>

<template>
  <p>{{ cart.qty }} × {{ cart.price }} = {{ cart.qty * cart.price }} ကျပ်</p>
  <button @click="addOne">ထပ်ထည့်</button>
</template>
Expected Output — စတင်ချိန်
2 × 1500 = 3000 ကျပ်

Object/array ကို တစ်ခုတည်း ကိုင်တွယ်ရင် reactive၊ primitive (number/string/boolean) နဲ့ function ကနေ ပြန်ပေးချင်ရင် ref ကို သုံးလေ့ရှိတယ်။ နှစ်မျိုးလုံး ရောနိုင်တယ်။

၃။ computed — တွက်ပြီး သိမ်းထား

Bill.vue VUE
<script setup>
import { ref, computed } from "vue";
const qty = ref(3);
const price = ref(1500);

const subtotal = computed(() => qty.value * price.value);
const vat = computed(() => Math.round(subtotal.value * 0.05));
const total = computed(() => subtotal.value + vat.value);
</script>

<template>
  <p>Subtotal: {{ subtotal }} ကျပ်</p>
  <p>VAT 5%: {{ vat }} ကျပ်</p>
  <p>စုစုပေါင်း: {{ total }} ကျပ်</p>
</template>
Expected Output — browser မှာ ပြမယ်
Subtotal: 4500 ကျပ်
VAT 5%: 225 ကျပ်
စုစုပေါင်း: 4725 ကျပ်

computed က မှီခိုတဲ့ တန်ဖိုး မပြောင်းသရွေ့ ပြန်မတွက်ဘူး (cache)။ Method ကို template မှာ ခေါ်ရင် render တိုင်း ပြန်တွက်တာမို့ တွက်ရ လေးတဲ့ အလုပ်အတွက် computed က ပိုကောင်းတယ်။

ဘယ်ဟာ သုံးမလဲ

ခေတ္တ တန်ဖိုး တစ်ခု → ref။ ဆက်စပ် ဒေတာ အုပ်စု → reactive။ အခြား ဒေတာကနေ ဆင်းသက်တဲ့ တန်ဖိုး → computed။ ဒေတာ ပြောင်းတဲ့ အချိန် ဘေးထွက် အလုပ် (API ခေါ်၊ localStorage သိမ်း) → watch (အခန်း ၈)။

အခန်း 05 · အသုံးပြုသူ နဲ့ ဆက်သွယ်မှု

Event နဲ့ v-model

Button နှိပ်တာ၊ input ရိုက်တာ — user ရဲ့ လုပ်ဆောင်ချက် တိုင်းက event ပါ။ @click နဲ့ ဖမ်းပြီး v-model နဲ့ ဖောင် တန်ဖိုးကို ဒေတာနဲ့ တိုက်ရိုက် ချိတ်တယ်။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • v-on / @ နဲ့ event ဖမ်းခြင်း
  • v-model နဲ့ form ချိတ်ခြင်း
  • Event modifier (.prevent, .stop)
  • ဖောင် တန်ဖိုး ပြောင်းတာကို စောင့်ကြည့်ခြင်း

၁။ Event ဖမ်းခြင်း

OrderForm.vue VUE
<script setup>
import { ref } from "vue";
const qty = ref(1);
const name = ref("");
const agree = ref(false);

function submit() {
  console.log(name.value, qty.value, agree.value);
}
</script>

<template>
  <input v-model.trim="name" placeholder="နာမည်">
  <input v-model.number="qty" type="number" min="1">
  <label><input type="checkbox" v-model="agree"> သဘောတူတယ်</label>
  <button @click="submit">မှာယူမယ်</button>
</template>
Expected Output — name="မောင်", qty=3, agree=true
မောင် 3 true

v-model က နှစ်လမ်းသွား ချိတ်ဆက်တယ် — input ရိုက်ရင် ဒေတာ ပြောင်း၊ ဒေတာ ပြောင်းရင် input ပြောင်း။ .trim က ကြားကွက် ဖြတ်၊ .number က စာသားကို နံပါတ် အဖြစ် ပြောင်းပေးတယ်။

၂။ Event Modifier

Modifierအလုပ်ဥပမာ
.preventDefault အလုပ် ပိတ်@submit.prevent="save"
.stopEvent ဆက်ပျံ့တာ ရပ်@click.stop
.selfကိုယ့် element ပဲ ဖြစ်မှ@click.self
.onceတစ်ခါပဲ လုပ်@click.once

၃။ Form နဲ့ ဆက်စပ် သတိထားချက်

Form ကို submit လုပ်ရင် page ပြန်လှန်တာ (refresh) မဖြစ်စေချင်ရင် @submit.prevent="save" သုံးပါ။ button ကို type="submit" ထားပြီး form ရဲ့ submit event မှာ ကိုင်တာက နည်းစနစ်ကျတယ် — Enter နှိပ်လည်း အလုပ်လုပ်တယ်။

ထောင်ချောက် — checkbox ရဲ့ default

v-model ကို checkbox မှာ သုံးရင် တန်ဖိုးက true/false ဖြစ်တယ်။ ref("") နဲ့ စထားရင် initial state မှာ “မှား” မဟုတ်ဘဲ ဗလာစာသား ဖြစ်နေတတ်တာမို့ ref(false) နဲ့ စပါ။

အခန်း 06 · ပြသ/ဖျောက် နဲ့ စာရင်း

v-if / v-for

ဒေတာ အခြေအနေ အလိုက် ပြရ/ဖျောက်ရ လိုတယ်။ စာရင်း တစ်ခုကို ထပ်ပြီး ပြရ လိုတယ်။ ဒါတွေကို v-if နဲ့ v-for က လုပ်ပေးတယ်။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • v-if / v-else-if / v-else
  • v-show နဲ့ ကွာခြားချက်
  • v-for နဲ့ :key
  • စာရင်း ပြတဲ့အခါ ဖြစ်တတ်တဲ့ ပြဿနာ

၁။ v-if နဲ့ v-show

Stock.vue VUE
<script setup>
import { ref } from "vue";
const stock = ref(0);
</script>

<template>
  <p v-if="stock > 10">လုံလောက်တယ် ({{ stock }})</p>
  <p v-else-if="stock > 0">နည်းနည်း ကျန်တယ် ({{ stock }})</p>
  <p v-else>ကုန်နေပြီ</p>

  <p v-show="stock === 0">⚠ ပြန်မှာယူပါ</p>
</template>
Expected Output — stock = 0
ကုန်နေပြီ
⚠ ပြန်မှာယူပါ
Directiveဘယ်လို လုပ်ဘယ်အခါ သုံး
v-ifDOM ကို ဖျက်/ပြန်ဆောက်ပြောင်းတာ ရှားတဲ့ အခါ
v-showCSS display:none ပဲမကြာခဏ ပြောင်းတဲ့ အခါ

၂။ v-for နဲ့ စာရင်း ပြခြင်း

ProductList.vue VUE
<script setup>
import { ref } from "vue";
const products = ref([
  { id: 1, name: "မီးသီး", price: 1500 },
  { id: 2, name: "ပလပ်စွပ်", price: 800 },
  { id: 3, name: "ကြိုး", price: 3200 }
]);
</script>

<template>
  <ul>
    <li v-for="p in products" :key="p.id">
      {{ p.name }} — {{ p.price.toLocaleString() }} ကျပ်
    </li>
  </ul>
</template>
Expected Output — browser မှာ ပြမယ်
မီးသီး — 1,500 ကျပ်
ပလပ်စွပ် — 800 ကျပ်
ကြိုး — 3,200 ကျပ်

:key က Vue ကို ဘယ် item က ဘယ်ဟာလဲ ခွဲသိစေတယ်။ Unique ဖြစ်တဲ့ id ကို သုံးပါ — index ကို key အဖြစ် သုံးရင် စာရင်း အလယ်က ဖျက်/ထည့်တဲ့အခါ မျက်နှာပြင် မှားနိုင်တယ်။

၃။ စာရင်း ထဲက ကို ဖြတ်ပြီး စစ်ခြင်း

Filter.vue VUE
<script setup>
import { ref, computed } from "vue";
const keyword = ref("");

const products = ref([
  { id: 1, name: "မီးသီး", price: 1500 },
  { id: 2, name: "ပလပ်စွပ်", price: 800 },
  { id: 3, name: "ကြိုး", price: 3200 }
]);

const filtered = computed(() =>
  products.value.filter(p => p.name.includes(keyword.value))
);
</script>

<template>
  <input v-model="keyword" placeholder="ရှာမယ်">
  <p v-if="filtered.length === 0">မတွေ့ပါ</p>
  <ul>
    <li v-for="p in filtered" :key="p.id">{{ p.name }}</li>
  </ul>
</template>

စာရင်း ပြတဲ့အခါ v-if နဲ့ ဗလာ အခြေအနေကို ပြဖို့ မမေ့ပါနဲ့ — user က “ဘာမှ မပြတာ” နဲ့ “မတွေ့တာ” ကို ခွဲသိဖို့ လိုတယ်။

v-if နဲ့ v-for ကို တစ်လုံးတည်း မတွဲပါနဲ့

Vue 3 မှာ v-if က v-for ထက် အရင် အလုပ်လုပ်တာမို့ item variable ကို v-if မှာ သုံးလို့ မရဘူး။ လိုအပ်ရင် စစ်ပြီးသား စာရင်းကို computed နဲ့ ပြင်ပြီးမှ v-for ပါ။

အခန်း 07 · ပြန်သုံးနိုင်တဲ့ အပိုင်း

Component (props / emit)

Component က မျက်နှာပြင် အပိုင်း တစ်ပိုင်းကို သီးခြား ဖိုင်နဲ့ ရေးတာပါ။ အပြင်က ဒေတာ ပေးပို့တာက props၊ အတွင်းက အပြင်ကို အသိပေးတာက emit ပါ။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • Component ဖန်တီး/ခေါ်သုံးပုံ
  • defineProps နဲ့ ဒေတာ လက်ခံခြင်း
  • defineEmits နဲ့ event ပို့ခြင်း
  • Slot နဲ့ အကြောင်းအရာ ထည့်ခြင်း

၁။ Component တစ်ခု ရေးခြင်း

components/ProductCard.vue VUE
<script setup>
const props = defineProps({
  name: { type: String, required: true },
  price: { type: Number, default: 0 }
});
const emit = defineEmits(["add"]);

function addToCart() {
  emit("add", props.name);
}
</script>

<template>
  <div class="card">
    <h3>{{ name }}</h3>
    <p>{{ price.toLocaleString() }} ကျပ်</p>
    <button @click="addToCart">စျေးခြင်းထဲ ထည့်</button>
  </div>
</template>

၂။ မိခင် component မှာ ခေါ်သုံးခြင်း

views/Shop.vue VUE
<script setup>
import { ref } from "vue";
import ProductCard from "@/components/ProductCard.vue";

const cart = ref([]);

function handleAdd(name) {
  cart.value.push(name);
  console.log("ထည့်ပြီး:", cart.value.join(", "));
}
</script>

<template>
  <ProductCard name="မီးသီး" :price="1500" @add="handleAdd" />
  <ProductCard name="ကြိုး" :price="3200" @add="handleAdd" />
</template>
Expected Output — နှစ်ခုလုံး နှိပ်ပြီးနောက် console
ထည့်ပြီး: မီးသီး, ကြိုး

Static တန်ဖိုးကို name="မီးသီး" လို ရိုးရိုး ရေးနိုင်တယ်။ Number/Boolean/variable ကို ပို့ရင် :price="1500" လို : ထည့်ရတယ်။ မထည့်ရင် စာသား "1500" ဖြစ်သွားတယ်။

၃။ Slot

components/Box.vue VUE
<template>
  <div class="box">
    <slot>အကြောင်းအရာ မထည့်ရင် ဒါ ပေါ်မယ်</slot>
  </div>
</template>

Slot က Component ကို “ဘောင်” အဖြစ် သုံးပြီး အတွင်းထည့်တဲ့ အကြောင်းအရာကို ပြောင်းလို့ရတယ်။ Modal၊ Card၊ Alert စတဲ့ ပုံစံ တူတဲ့ အပိုင်းတွေအတွက် အသုံးဝင်တယ်။

ထောင်ချောက် — props ကို ပြင်လို့မရ

Child ထဲမှာ props.price = 2000 လို ပြင်တာ error ပြတယ် (one-way data flow)။ ပြင်ချင်ရင် emit နဲ့ မိခင်ကို အသိပေးပြီး မိခင်က ပြင်ရတယ်။ ဒါက ဒေတာ စီးဆင်းမှုကို ရှင်းစေတယ်။

အခန်း 08 · အချိန်နဲ့ အစဉ်

Lifecycle နဲ့ watch

Component တစ်ခုက စတင် ပေါ်လာတဲ့အခါ၊ ပျက်သွားတဲ့အခါ လုပ်ရမယ့် အလုပ် ရှိတယ် — API ခေါ်တာ၊ timer ရပ်တာ။ Lifecycle hook တွေက အဲဒီ အချိန်တွေမှာ ဝင်လုပ်ခွင့်ပေးတယ်။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • onMounted / onUnmounted
  • watch နဲ့ watchEffect
  • ဘယ်အလုပ်ကို ဘယ် hook မှာ ထားမလဲ
  • Memory leak မဖြစ်အောင် ရှင်းလင်းခြင်း

၁။ Mount နဲ့ Unmount

Clock.vue VUE
<script setup>
import { ref, onMounted, onUnmounted } from "vue";
const time = ref(new Date().toLocaleTimeString());
let timerId = null;

onMounted(() => {
  timerId = setInterval(() => {
    time.value = new Date().toLocaleTimeString();
  }, 1000);
});

onUnmounted(() => {
  clearInterval(timerId);   // မရှင်းရင် memory leak
});
</script>

<template>
  <p>{{ time }}</p>
</template>
Expected Output — စက္ကန့်တိုင်း ပြောင်းမယ်
2:31:05 PM

၂။ watch

SaveForm.vue VUE
<script setup>
import { ref, watch } from "vue";
const name = ref("");

watch(name, (newValue, oldValue) => {
  console.log("ပြောင်း:", oldValue, "→", newValue);
  localStorage.setItem("draft-name", newValue);
});
</script>

<template>
  <input v-model="name" placeholder="နာမည်">
</template>
Expected Output — "မ" ပြီး "မော" ရိုက်ရင်
ပြောင်း:  → မ
ပြောင်း: မ → မော

watch က ဒေတာ ပြောင်းတာကို စောင့်ကြည့်ပြီး ဘေးထွက် အလုပ် လုပ်တယ်။ watchEffect ကတော့ အတွင်းက ဖတ်ထားတဲ့ ဒေတာကို အလိုအလျောက် လိုက်ကြည့်တယ် — ရှင်းရှင်း သိထားတဲ့ အခြေအနေ ရှိရင် watch က ပိုထိန်းချုပ်ရလွယ်တယ်။

လုပ်ချင်တာသုံးရမယ့် နည်း
Component ပေါ်ပြီးမှ API ခေါ်onMounted
Component မပျက်ခင်မှာ timer/event ရှင်းonUnmounted
ဒေတာ ပြောင်းတိုင်း သိမ်း/ခေါ်watch
ဒေတာကနေ ဆင်းသက်တဲ့ တန်ဖိုးcomputed
API ခေါ်တာကို ဘယ်မှာ ထားမလဲ

Component ပေါ်တာနဲ့ တစ်ခါ ခေါ်ချင်ရင် onMounted မှာ ထားပါ။ Filter ပြောင်းတိုင်း ပြန်ခေါ်ချင်ရင် watch မှာ ထားပါ။ တစ်ခါတည်း နှစ်နေရာ ခေါ်မိရင် request နှစ်ခါ ထွက်တာမို့ သတိထားပါ။

အခန်း 09 · မျက်နှာပြင် အကြား သွားလာ

Vue Router

SPA မှာ page တွေ မလှန်ဘဲ URL အလိုက် မျက်နှာပြင် ပြောင်းတာကို Vue Router က လုပ်ပေးတယ်။ /products/3 လို URL တစ်ခုစီမှာ မတူတဲ့ မျက်နှာပြင် ပြနိုင်တယ်။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • Route သတ်မှတ်ပုံ
  • RouterLink / RouterView
  • URL parameter ဖတ်ပုံ
  • Programmatic navigation

၁။ Route သတ်မှတ်ခြင်း

src/router/index.js JS
import { createRouter, createWebHistory } from "vue-router";
import Home from "@/views/Home.vue";
import ProductList from "@/views/ProductList.vue";
import ProductDetail from "@/views/ProductDetail.vue";

const router = createRouter({
  history: createWebHistory(),
  routes: [
    { path: "/", component: Home },
    { path: "/products", component: ProductList },
    { path: "/products/:id", component: ProductDetail }
  ]
});

export default router;

၂။ ချိတ်ဆက်ခြင်းနဲ့ ပြသခြင်း

src/App.vue VUE
<template>
  <nav>
    <RouterLink to="/">ပင်မ</RouterLink>
    <RouterLink to="/products">ပစ္စည်းများ</RouterLink>
  </nav>

  <RouterView />
</template>

၃။ URL parameter ဖတ်ခြင်း

views/ProductDetail.vue VUE
<script setup>
import { useRoute, useRouter } from "vue-router";
const route = useRoute();
const router = useRouter();

function goBack() {
  router.push("/products");
}
</script>

<template>
  <p>ပစ္စည်း ID: {{ route.params.id }}</p>
  <button @click="goBack">စာရင်းသို့</button>
</template>
Expected Output — URL: /products/3
ပစ္စည်း ID: 3

Link အတွက် <RouterLink> ကို သုံးပါ — <a href> က page ကို အပြည့် ပြန်တင်တာမို့ SPA ရဲ့ ကောင်းချက် ပျောက်တယ်။ Code ကနေ ပြောင်းချင်ရင် router.push() သုံးပါ။

ထောင်ချောက် — route param က စာသား

route.params.id က string ဖြစ်တယ်။ နံပါတ်နဲ့ နှိုင်းယှဉ်ရင် Number(route.params.id) === 3 လို့ ပြောင်းပါ။ မပြောင်းရင် "3" === 3 က false ဖြစ်တယ်။

အခန်း 10 · မျှဝေ အခြေအနေ

Pinia (State Management)

Component တွေ အများကြီး ရှိလာရင် ဒေတာကို မိခင်-သားစဉ် props နဲ့ သာ ပို့နေရင် ရှုပ်တယ်။ Pinia store က ဒေတာကို တစ်နေရာတည်းမှာ သိမ်းပြီး ဘယ် component ကမဆို ယူသုံးလို့ ရစေတယ်။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • Store ဖန်တီးပုံ
  • state / getters / actions
  • Component ထဲမှာ ယူသုံးပုံ
  • Store ကို ဘယ်အခါ လိုအပ်လဲ

၁။ Store ဖန်တီးခြင်း

src/stores/cart.js JS
import { defineStore } from "pinia";

export const useCartStore = defineStore("cart", {
  state: () => ({
    items: []
  }),
  getters: {
    count: (state) => state.items.length,
    total: (state) => state.items.reduce((sum, p) => sum + p.price, 0)
  },
  actions: {
    add(product) {
      this.items.push(product);
    }
  }
});

၂။ Component ထဲမှာ သုံးခြင်း

views/Cart.vue VUE
<script setup>
import { useCartStore } from "@/stores/cart";
const cart = useCartStore();

cart.add({ name: "မီးသီး", price: 1500 });
</script>

<template>
  <p>ပစ္စည်း: {{ cart.count }} မျိုး</p>
  <p>စုစုပေါင်း: {{ cart.total }} ကျပ်</p>
</template>
Expected Output — browser မှာ ပြမယ်
ပစ္စည်း: 1 မျိုး
စုစုပေါင်း: 1500 ကျပ်

Store ကို main.js မှာ app.use(createPinia()) တစ်ခါ ထည့်ထားဖို့ လိုတယ်။ Store ထဲက state ကို တိုက်ရိုက် ပြင်တာထက် action ကတစ်ဆင့် ပြင်တာက စည်းကမ်းရှိတယ် — ဘယ် အလုပ်တွေ လုပ်လဲ ကြည့်ရ လွယ်တယ်။

Pinia ကို ဘယ်အခါ လိုလဲ

ဒေတာကို component အနည်းငယ်ပဲ သုံးရင် props/emit က လုံလောက်တယ်။ မျက်နှာပြင် များစွာက ဒေတာ တစ်ခုတည်းကို ကြည့်ရ/ပြင်ရ (login user၊ cart၊ theme) ဖြစ်လာရင် Pinia က ပိုသင့်တယ်။

အခန်း 11 · အပြင်က ဒေတာ ယူခြင်း

Fetch API နဲ့ Loading / Error

တကယ့် app တွေက ဒေတာကို server/API ကနေ ယူတယ်။ ဒေတာ မရောက်သေးတဲ့ အချိန်၊ မရတဲ့ အချိန် ကို user ကို ပြဖို့ လိုတယ်။ ဒီခန်းမှာ သုံးမျိုး အခြေအနေ (loading / error / data) ကို စီမံတာ လေ့လာမယ်။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • fetch ကို async/await နဲ့ ခေါ်ပုံ
  • Loading/Error/Data အခြေအနေ ခွဲပြပုံ
  • API endpoint ကို env variable နဲ့ ထားပုံ
  • Error ကို user ကို ဘယ်လို ပြမလဲ

၁။ fetch နဲ့ ဒေတာ ယူခြင်း

ProductList.vue VUE
<script setup>
import { ref, onMounted } from "vue";

const products = ref([]);
const loading = ref(false);
const error = ref("");

onMounted(async () => {
  loading.value = true;
  try {
    const res = await fetch("/api/products");
    if (!res.ok) throw new Error("HTTP " + res.status);
    products.value = await res.json();
  } catch (err) {
    error.value = "ဒေတာ ယူမရပါ — ထပ်စမ်းပါ";
    console.error(err);
  } finally {
    loading.value = false;
  }
});
</script>

<template>
  <p v-if="loading">ခဏစောင့်ပါ...</p>
  <p v-else-if="error">{{ error }}</p>
  <ul v-else>
    <li v-for="p in products" :key="p.id">{{ p.name }}</li>
  </ul>
</template>
Expected Output — သုံးမျိုး အခြေအနေ
① ခဏစောင့်ပါ...
② ဒေတာ ယူမရပါ — ထပ်စမ်းပါ      (HTTP 500 ဖြစ်ရင်)
③ • မီးသီး
   • ပလပ်စွပ်                      (အောင်မြင်ရင်)

fetch က HTTP 404/500 မှာ error မပစ်ဘူး — res.ok ကို ကိုယ်တိုင် စစ်ရတယ်။ Status မစစ်ရင် error page ရဲ့ HTML ကို JSON လို့ ဖတ်မိတာ ဖြစ်တတ်တယ်။

၂။ POST ပို့ခြင်း

api.js JS
const API = import.meta.env.VITE_API_URL || "/api";

export async function createProduct(data) {
  const res = await fetch(API + "/products", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(data)
  });
  if (!res.ok) throw new Error("သိမ်းမရပါ (" + res.status + ")");
  return res.json();
}

API URL ကို code ထဲ ရေးမထားပါနဲ့။ .env ဖိုင်မှာ VITE_API_URL=https://api.example.com လို ထားပြီး import.meta.env နဲ့ ဖတ်ပါ — dev နဲ့ production URL ကို လွယ်လွယ် ပြောင်းနိုင်တယ်။

ထောင်ချောက် — key မပါတဲ့စာရင်း

API က id မပေးရင် :key မှာ p.name သုံးရတတ်တယ်။ နာမည် ထပ်နေရင်တော့ key ထပ်ပြီး render မှားတယ်။ API ဒီဇိုင်း ရွေးချယ်တဲ့အခါ id တစ်ခု ပါအောင် သတ်မှတ်ထားတာ အကောင်းဆုံးပါ။

အခန်း 12 · App ကို ထုတ်ခြင်း

Build နဲ့ Deploy

ရေးထားတဲ့ .vue ဖိုင်တွေကို browser က တိုက်ရိုက် မဖတ်နိုင်ဘူး။ Build လုပ်တဲ့အခါ HTML/CSS/JS ဖိုင်တွေ အဖြစ် ပြောင်းပြီး dist/ ဖိုဒါထဲ ထည့်ပေးတယ်။ အဲဒါကို hosting မှာ တင်ရတယ်။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • npm run build က ဘာ လုပ်လဲ
  • Build ရလဒ်ကို စမ်းကြည့်ပုံ
  • Static hosting မှာ တင်ပုံ
  • Subfolder မှာ တင်ရင် ဖြစ်တတ်တဲ့ ပြဿနာ

၁။ Build လုပ်ခြင်း

terminal BASH
npm run build
npm run preview
Expected Output — Vite build ရလဒ်
vite v6.x building for production...
✓ 42 modules transformed.
dist/index.html                  0.46 kB
dist/assets/index-8f2a1c.css    12.84 kB
dist/assets/index-3d9b71.js     64.20 kB
✓ built in 1.42s

➜  Local:   http://localhost:4173/

npm run preview က build ရလဒ်ကို တကယ့် hosting လို စမ်းပြပေးတယ်။ Dev server မှာ ကောင်းနေလျက်နဲ့ build မှာ မရတာတွေ ရှိတာမို့ တင်ခင် preview မှာ စမ်းပါ။

၂။ Hosting မှာ တင်ခြင်း

Hostingဘယ်လို တင်မှတ်ချက်
Netlify / VercelGit repo ချိတ်၊ build command npm run build၊ output distအလွယ်ဆုံး
GitHub Pagesdist ကို gh-pages branch သို့ တင်Subfolder URL အတွက် base သတ်မှတ်ရ
ကိုယ်ပိုင် serverdist ကို web root မှာ ကော်ပီHistory mode အတွက် fallback လိုအပ်
Refresh လုပ်တိုင်း 404 ဖြစ်ရင်

createWebHistory() သုံးထားရင် /products ကို တိုက်ရိုက် ဖွင့်တဲ့အခါ server မှာ ဖိုင် မရှိတာမို့ 404 ပြတယ်။ SPA hosting ရဲ့ “redirect all to index.html” setting ကို ဖွင့်ပါ (Netlify မှာ _redirects ဖိုင်၊ Vercel မှာ rewrites)။

အခန်း 13 · UI Framework

Quasar မိတ်ဆက်

Quasar က Vue 3 အတွက် UI component တွေ အသင့် ပေးထားတဲ့ framework ပါ။ ဒီတစ်ခုတည်းနဲ့ website၊ PWA၊ Android/iOS app၊ desktop app ကို code တစ်စုတည်းကနေ ထုတ်နိုင်တယ်။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • Quasar က ဘာအတွက် ကောင်းလဲ
  • Project ဖန်တီး/run ပုံ
  • ဖိုဒါ တည်ဆောက်ပုံ
  • Vue ချည်းသက်သက်နဲ့ ကွာခြားချက်

၁။ Project ဖန်တီးခြင်း

terminal BASH
npm init quasar
cd shop-app
npm install
quasar dev
Expected Output — dev server စတင်
 App •  QUASAR  •  quasar dev
 App •  Dev server listening at http://localhost:9000/

မေးခွန်း တွေကို ဖြေတဲ့အခါ “Vue 3 + Vite” နဲ့ “Material Icons” ကို ရွေးထားပါ။ Quasar CLI က quasar dev၊ quasar build လို command ကို တစ်နေရာတည်းက ပေးတယ်။

၂။ ဖိုဒါ တည်ဆောက်ပုံ

ဖိုဒါ/ဖိုင်တာဝန်
src/pages/Route တစ်ခုစီရဲ့ မျက်နှာပြင်
src/components/ပြန်သုံး ပစ္စည်းများ
src/layouts/Header/Drawer ပါ တူညီ ဘောင်
src/router/routes.jsRoute စာရင်း
quasar.config.jsBuild၊ plugin၊ boot ဖိုင် သတ်မှတ်ချက်
src/boot/App မစခင် run မယ့် ကုဒ်
Quasar သုံးရင် ရမယ့် အကျိုး

Button၊ Table၊ Dialog၊ Date picker စတဲ့ UI ကို ကိုယ်တိုင် CSS ရေးစရာ မလိုဘဲ ရနိုင်တယ်။ ဖုန်း၊ တက်ဘလက်၊ desktop အတွက် အလိုအလျောက် လိုက်လျောညီထွေ ဖြစ်တယ်။ ဒါပေမယ့် app ကို Quasar ရဲ့ စည်းကမ်းနဲ့ လိုက်ရတာမို့ ရိုးရိုး Vue ထက် အလေ့အကျင့် နည်းနည်း ပိုလိုတယ်။

အခန်း 14 · အသင့် UI ပစ္စည်းများ

Quasar Components

q-btn၊ q-input၊ q-table၊ q-dialog တွေက Quasar ရဲ့ အသုံးအများဆုံး component တွေပါ။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • q-input နဲ့ validation
  • q-table နဲ့ စာရင်း ပြခြင်း
  • q-dialog နဲ့ Notify
  • အရောင်/ပုံစံ ပြောင်းပုံ

၁။ Form နဲ့ validation

pages/AddProduct.vue VUE
<script setup>
import { ref } from "vue";
import { useQuasar } from "quasar";

const $q = useQuasar();
const name = ref("");
const price = ref(null);
const nameRef = ref(null);

function save() {
  nameRef.value.validate();
  if (nameRef.value.hasError) return;
  $q.notify({ type: "positive", message: "သိမ်းပြီးပါပြီ" });
  name.value = "";
  price.value = null;
}
</script>

<template>
  <q-input ref="nameRef" v-model="name" label="ပစ္စည်း အမည်"
    :rules="[v => !!v || 'နာမည် ထည့်ပါ']" />
  <q-input v-model.number="price" type="number" label="စျေးနှုန်း"
    :rules="[v => v > 0 || 'စျေးနှုန်း ထည့်ပါ']" />
  <q-btn color="primary" label="သိမ်း" @click="save" />
</template>
Expected Output — နာမည် မထည့်ဘဲ “သိမ်း” နှိပ်ရင်
ပစ္စည်း အမည်
[ နာမည် ထည့်ပါ ]        ← input အောက်မှာ အနီရောင် ပြ

rules က true ပြန်ရင် အောင်မြင်၊ string ပြန်ရင် အဲဒီ စာသားကို error အဖြစ် ပြတယ်။ Form တစ်ခုလုံး စစ်ချင်ရင် q-form နဲ့ ခြုံပြီး validate() ခေါ်တာ ပိုရှင်းတယ်။

၂။ Table

pages/Products.vue VUE
<script setup>
const columns = [
  { name: "name", label: "အမည်", field: "name", align: "left" },
  { name: "price", label: "စျေးနှုန်း", field: "price", sortable: true },
  { name: "qty", label: "လက်ကျန်", field: "qty", sortable: true }
];
const rows = [
  { id: 1, name: "မီးသီး", price: 1500, qty: 24 },
  { id: 2, name: "ကြိုး", price: 3200, qty: 8 }
];
</script>

<template>
  <q-table :columns="columns" :rows="rows" row-key="id" />
</template>

sortable: true ထည့်ထားတဲ့ column ကို ခေါင်းစီး နှိပ်ရင် အစဉ်လိုက် ဖြစ်တယ်။ Row အရေအတွက် များရင် :rows-per-page-options="[10, 20, 50]" နဲ့ pagination ထည့်နိုင်တယ်။

၃။ Dialog နဲ့ Notify

pages/DeleteConfirm.vue VUE
<script setup>
import { ref } from "vue";
import { useQuasar } from "quasar";
const $q = useQuasar();
const confirmOpen = ref(false);

function doDelete() {
  confirmOpen.value = false;
  $q.notify({ type: "negative", message: "ဖျက်ပြီးပါပြီ" });
}
</script>

<template>
  <q-btn color="negative" label="ဖျက်" @click="confirmOpen = true" />
  <q-dialog v-model="confirmOpen">
    <q-card>
      <q-card-section>တကယ် ဖျက်မလား?</q-card-section>
      <q-card-actions align="right">
        <q-btn flat label="မလုပ်တော့" v-close-popup />
        <q-btn color="negative" label="ဖျက်မည်" @click="doDelete" />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>
Expected Output — ဖျက် နှိပ်ပြီးနောက်
[ ဖျက်မလား? ] → “ဖျက်မည်” နှိပ်ရင် ညာဘက်အောက်
အနီရောင် toast: ဖျက်ပြီးပါပြီ
Notify ကို တစ်ခါ ဖွင့်ထားဖို့ လိုတယ်

$q.notify မပေါ်ရင် quasar.config.js ရဲ့ framework.plugins မှာ "Notify" ထည့်ထားခြင်း မရှိလို့ ဖြစ်နိုင်တယ်။ ဒါကို မေ့ရင် error မပြတဲ့ဘဲ toast ပျောက်နေတယ်။

အခန်း 15 · ဘောင် တည်ဆောက်ပုံ

Layout (Header / Drawer / Page)

မျက်နှာပြင် တိုင်းမှာ ထိပ်ဘား နဲ့ ဘေး မီနူး ရှိတယ်။ Layout ကို တစ်ခါ ရေးပြီး page တွေ အားလုံး အဲဒီထဲ ထည့်တာမို့ ထပ် မရေးရတော့ဘူး။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • q-layout ရဲ့ အစိတ်အပိုင်းများ
  • Drawer ကို ဖုန်းမှာ ဖျောက်ခြင်း
  • Screen size အလိုက် ပြောင်းခြင်း
  • Dark mode

၁။ Layout အခြေခံ

layouts/MainLayout.vue VUE
<script setup>
import { ref } from "vue";
const drawer = ref(true);
</script>

<template>
  <q-layout view="hHh lpR fFf">
    <q-header elevated>
      <q-toolbar>
        <q-btn flat icon="menu" @click="drawer = !drawer" />
        <q-toolbar-title>NCT စျေးဆိုင်</q-toolbar-title>
      </q-toolbar>
    </q-header>

    <q-drawer v-model="drawer" :width="240" show-if-above>
      <q-list>
        <q-item to="/" clickable>
          <q-item-section>ပင်မ</q-item-section>
        </q-item>
        <q-item to="/products" clickable>
          <q-item-section>ပစ္စည်းများ</q-item-section>
        </q-item>
      </q-list>
    </q-drawer>

    <q-page-container>
      <router-view />
    </q-page-container>
  </q-layout>
</template>

show-if-above က မျက်နှာပြင် ကျယ်ရင် drawer ကို အမြဲ ပြထားတယ်။ ဖုန်းမှာ ဖျောက်ပြီး မီနူး နှိပ်မှ ပေါ်လာတယ်။ router-view ရှိတဲ့ နေရာမှာ page အလိုက် မျက်နှာပြင် ပြောင်းတယ်။

၂။ Screen size နဲ့ Dark mode

pages/Dashboard.vue VUE
<script setup>
import { useQuasar } from "quasar";
const $q = useQuasar();

function toggleDark() {
  $q.dark.toggle();
}
</script>

<template>
  <div :class="$q.screen.lt.md ? 'column' : 'row'">
    <q-card class="col">ယနေ့ ရောင်းအား</q-card>
    <q-card class="col">လက်ကျန်</q-card>
  </div>
  <q-btn label="Dark/Light" @click="toggleDark" />
</template>
Toolအဓိပ္ပာယ်
$q.screen.lt.mdmd ထက် သေးတယ် (ဖုန်း)
$q.screen.gt.smsm ထက် ကြီးတယ် (desktop)
$q.dark.toggle()Dark/Light လှည့်
ထောင်ချောက် — Layout ကို page အလိုက် မရေးပါနဲ့

Page တိုင်းမှာ q-layout ထပ်ရေးရင် ထိပ်ဘား တစ်ခါ၊ ကျောက်တစ်ခါ လှုပ်နိုင်တယ်။ Layout ကို src/layouts/ မှာ တစ်ခုတည်း ထားပြီး routes မှာ component: MainLayout နဲ့ ခြုံပါ။

အခန်း 16 · ထုတ်လုပ်ခြင်း

Build / PWA / Mobile App

Quasar မှာ ထုတ်ချင်တဲ့ ပုံစံကို -m နဲ့ ရွေးတယ်။ တူညီတဲ့ code ကနေ website၊ install လုပ်လို့ရတဲ့ PWA၊ Android/iOS app ကို ထုတ်နိုင်တယ်။

ဒီခန်း ပြီးရင် သိလာမယ့် အချက်

  • SPA / PWA / Capacitor / Electron ကွာခြားချက်
  • Build command နဲ့ ရလဒ် ဖိုဒါ
  • PWA အတွက် လိုအပ်ချက်
  • ဘယ်ဟာကို ဘယ်အခါ ရွေးမလဲ

၁။ Mode ရွေးခြင်း

terminal BASH
quasar build -m spa
quasar build -m pwa
quasar build -m capacitor -T android
Expected Output — SPA build
 Build succeeded
 dist/spa/index.html
 dist/spa/assets/app-4b7c9d.js
Modeရလဒ်သုံးရမယ့် အခြေအနေ
SPAStatic ဖိုင်များNetlify/Vercel မှာ website
PWAInstall လုပ်နိုင်၊ offline ဖတ်နိုင်ဖုန်းမှာ browser ကနေ install စေချင်
CapacitorAndroid/iOS projectPlay Store/App Store မှာ တင်ချင်
ElectronWindows/Mac/Linux appDesktop မှာ ထည့်သွင်းချင်

၂။ PWA ဖြစ်ဖို့

quasar.config.js JS
pwa: {
  manifest: {
    name: "NCT စျေးဆိုင်",
    short_name: "NCT",
    description: "လျှပ်စစ်ပစ္စည်း စျေးဆိုင် app",
    start_url: "/",
    display: "standalone",
    theme_color: "#2563eb",
    icons: [{ src: "icons/icon-512x512.png", sizes: "512x512", type: "image/png" }]
  }
}

PWA install ခလုတ် ပေါ်ဖို့ HTTPS (သို့ localhost) လိုတယ်။ manifest နဲ့ service worker ကို Quasar က build လုပ်တဲ့အခါ အလိုအလျောက် ထည့်ပေးတာမို့ setting မှန်ရင် ချက်ချင်း ရနိုင်တယ်။

App store မတင်ခင်

Capacitor mode မှာ npx cap add android ပြီး Android Studio နဲ့ ဖွင့်တယ်။ တကယ် ဖုန်းမှာ စမ်းဖို့ USB debugging လိုတယ်။ Store မှာ တင်ရင် signing key နဲ့ privacy policy လိုတာမို့ ဒီအဆင့်ကို ကိုယ်ပိုင် lab မှာ သာစမ်းပါ။

အခန်း 17 · လေ့ကျင့်ခန်း

မေးခွန်း ၁၂ ဖြေကြည့်ပြီး အဖြေ ဖွင့်ကြည့်ပါ

အခန်း ၁–၁၆ ကို အခြေခံထားတဲ့ မေးခွန်း ၁၂ ပုဒ်ပါ။ ကိုယ်တိုင် အဖြေ စဉ်းစားပြီးမှ ကလစ်ပြီး ဖွင့်ကြည့်ပါ။ မှားတဲ့ မေးခွန်းရဲ့ “ပြန်ဖတ်” လင့်ခ်ကို နှိပ်ပြီး အခန်းကို ပြန်ဖတ်ပါ။

သုံးပုံ

Code ဥပမာတွေကို ကိုယ်ပိုင် project မှာ ရိုက်ထည့်ပြီး browser မှာ ပြောင်းကြည့်ပါ။ Vue မှာ “ဘာကြောင့် ဒီလို ရလဲ” ကို ရှင်းနိုင်ရင် အသိခိုင်ပြီ။

Vue အခြေခံ

၁။ Vue ကို CDN နဲ့ သုံးတာနဲ့ Vite project နဲ့ သုံးတာ ဘာကွာလဲ။
အဖြေ — CDN က build မလိုဘဲ စမ်းလို့ရ၊ Vite က တကယ့် app အတွက်။ ဘာကြောင့်လဲ — CDN က script တစ်ကြောင်း ထည့်ပြီး HTML ထဲ တိုက်ရိုက် ရေးတာမို့ သင်ယူဖို့ လွယ်တယ်။ Vite က .vue ဖိုင်၊ component၊ router၊ build လုပ်တာတွေ ပါတာမို့ project တကယ် ဆောက်ရင် Vite သုံးတယ်။အခန်း ၂ · Setup ပြန်ဖတ်
၂။ ref နဲ့ reactive က ဘာကွာလဲ။
အဖြေ — ref က တန်ဖိုး မျိုးစုံ (number, string, object) ကို ထည့်နိုင်၊ script ထဲမှာ .value နဲ့ ဖတ်ရ။ ဘာကြောင့်လဲ — reactive က object/array ပဲ လက်ခံပြီး property ကို တိုက်ရိုက် ဖတ်တယ်။ ရိုးရှင်းတဲ့ တန်ဖိုး တစ်ခုတည်း အတွက် ref က ပိုသင့်တယ်။အခန်း ၄ · Reactivity ပြန်ဖတ်
၃။ Template ထဲမှာ {{ count }} လို့ ရေးရင် .value မလိုဘူးလား။
အဖြေ — Template မှာ Vue က အလိုအလျောက် ဖြေပေးတာမို့ .value မလိုဘူး။ ဘာကြောင့်လဲ — <script setup> က ပြင်ဆင်ထားတဲ့ ref ကို template မှာ unwrap လုပ်ပေးတယ်။ count.value လို့ ရေးရင်တော့ မှားတယ် (template မှာ value က မရှိ)။ Script ထဲမှာတော့ count.value ပဲ။အခန်း ၃ · Template ပြန်ဖတ်
၄။ computed ကို ဘာကြောင့် သုံးလဲ။ method နဲ့ မတူဘူးလား။
အဖြေ — computed က ဒေတာ မပြောင်းသရွေ့ ရလဒ်ကို cache ထားတယ်။ ဘာကြောင့်လဲ — Method ကို template မှာ ခေါ်တိုင်း ပြန်တွက်တယ်။ စာရင်း ကြီးတဲ့အခါ ထပ်ခါ မတွက်ရအောင် computed က မှီခိုတဲ့ ဒေတာ ပြောင်းမှ ပြန်တွက်တယ်။အခန်း ၄ · Reactivity ပြန်ဖတ်
၅။ v-model.trim နဲ့ v-model.number က ဘာလုပ်လဲ။
အဖြေ — trim က ရှေ့/နောက် ကွက်လပ် ဖြတ်၊ number က စာသားကို နံပါတ် ပြောင်း။ ဘာကြောင့်လဲ — Input က အမြဲ string ပြန်တယ်။ နံပါတ် လိုတဲ့ နေရာမှာ .number မထည့်ရင် "3" + 1 က "31" ဖြစ်တယ်။ နာမည်/ရှာချက် မှာ .trim က မလိုချင်တဲ့ ကွက်လပ် ဖြတ်တယ်။အခန်း ၅ · Event ပြန်ဖတ်

Component နဲ့ Router

၆။ Child component က props ကို ပြင်လို့ ရလား။
အဖြေ — မရဘူး၊ emit နဲ့ မိခင်ကို အသိပေးပြီး မိခင်က ပြင်ရတယ်။ ဘာကြောင့်လဲ — Props က one-way ဖြစ်တယ်။ Child က ပြင်ရင် ဒေတာ ဘယ်ကနေ လာလဲ ရှုပ်သွားတယ်။ defineEmits နဲ့ event ပို့ပြီး ပိုင်ရှင် component က state ကို ပြင်ရတယ်။အခန်း ၇ · Component ပြန်ဖတ်
၇။ v-for မှာ :key က ဘာကြောင့် လိုတာလဲ။
အဖြေ — Item တစ်ခုစီကို Vue ခွဲသိဖို့ unique တန်ဖိုး ပေးတာ။ ဘာကြောင့်လဲ — စာရင်း အလယ်က ဖျက်/ထည့်တဲ့အခါ key မရှိရင် Vue က index နဲ့ ခွဲပြီး input တန်ဖိုး စတာတွေ မှားနိုင်တယ်။ id လို တည်ငြိမ်တဲ့ တန်ဖိုး သုံးပါ။အခန်း ၆ · v-if / v-for ပြန်ဖတ်
၈။ Component ပေါ်တာနဲ့ API ခေါ်ချင်ရင် ဘယ် hook မှာ ထားမလဲ။
အဖြေ — onMounted မှာ ထားပါ။ ဘာကြောင့်လဲ — onMounted က DOM ပေါ်ပြီးမှ run တာမို့ ဒေတာ ပြဖို့ အသင့် ဖြစ်တယ်။ Timer/event ထည့်ထားရင် onUnmounted မှာ ရှင်းဖို့ မမေ့ပါနဲ့။အခန်း ၈ · Lifecycle ပြန်ဖတ်
၉။ route.params.id နဲ့ နံပါတ် နှိုင်းယှဉ်တာ ဘာကြောင့် မမှန်တာလဲ။
အဖြေ — URL param က စာသား (string) ဖြစ်တာမို့ Number() နဲ့ ပြောင်းရတယ်။ ဘာကြောင့်လဲ — "3" === 3 က false ဖြစ်တယ်။ Number(route.params.id) === 3 လို ပြောင်းပြီးမှ နှိုင်းယှဉ်ပါ။အခန်း ၉ · Router ပြန်ဖတ်

State, API နဲ့ Quasar

၁၀။ Pinia ကို ဘယ်အခါ သုံးသင့်လဲ။
အဖြေ — Component များစွာက ဒေတာ တစ်ခုတည်းကို ကြည့်/ပြင်ရင်။ ဘာကြောင့်လဲ — Login user၊ cart၊ theme လို ဒေတာကို props နဲ့ အဆင့်ဆင့် ပို့နေရင် ရှုပ်တယ်။ Store တစ်ခုမှာ ထားပြီး လိုတဲ့ နေရာက ယူသုံးတာ ရှင်းတယ်။ Component နည်းရင် props/emit က လုံလောက်တယ်။အခန်း ၁၀ · Pinia ပြန်ဖတ်
၁၁။ fetch က 404 ရလာရင် catch ထဲ ဝင်လား။
အဖြေ — မဝင်ဘူး၊ res.ok ကို ကိုယ်တိုင် စစ်ရတယ်။ ဘာကြောင့်လဲ — fetch က network ပြတ်တာမှ error ပစ်တယ်။ HTTP 404/500 က response ရတာမို့ resolve ဖြစ်တယ်။ if (!res.ok) throw ... မထည့်ရင် error page ကို JSON လို့ ဖတ်မိတယ်။အခန်း ၁၁ · Fetch ပြန်ဖတ်
၁၂။ Quasar မှာ -m spa နဲ့ -m pwa ကွာခြားချက်က ဘာလဲ။
အဖြေ — spa က static website ဖိုင်၊ pwa က install/offline ပါတဲ့ app ဖြစ်တယ်။ ဘာကြောင့်လဲ — dist/spa ကို hosting မှာ တင်တယ်။ PWA က manifest + service worker ပါတာမို့ ဖုန်း မျက်နှာပြင်မှာ install လုပ်နိုင်၊ offline ဖတ်နိုင်တယ်။ HTTPS လိုတယ်။အခန်း ၁၆ · Build ပြန်ဖတ်
နောက်တစ်ဆင့်

npm create vue@latest နဲ့ project တစ်ခု ဖန်တီးပြီး ပစ္စည်း စာရင်း + cart + router ၃ မျက်နှာပြင် လုပ်ကြည့်ပါ။ ပြီးရင် Quasar project နဲ့ အလားတူ app ကို ပြန်ဆောက်ကြည့်ပါ — နှစ်ခု ကွာခြားချက်ကို ကိုယ်တွေ့ သိလာမယ်။

အခန်း 18 · MCQ လေ့ကျင့်ခန်း

ရွေးချယ်မေးခွန်း ၁၀ အမှတ် တွက်ကြည့်ပါ

မေးခွန်း တစ်ခုစီမှာ က) ခ) ဂ) ဃ) ထဲက မှန်တဲ့ အဖြေ တစ်ခုကို ရွေးပါ။ အားလုံး ရွေးပြီးရင် “အဖြေစစ်မယ်” ကို နှိပ်ပြီး အမှတ် ကြည့်ပါ။ မှားတဲ့ မေးခွန်းမှာ မှန်တဲ့အဖြေကို အစိမ်းရောင်၊ ကိုယ်ရွေးလိုက်တဲ့ အမှားကို အနီရောင် ပြပေးပါတယ်။

၁Template မှာ ref တန်ဖိုးကို ဘယ်လို ပြမလဲ (count က ref)။

၂<script setup> ထဲမှာ count (ref) ကို မှန်ကန်စွာ တိုးတဲ့ နည်းက ဘယ်ဟာလဲ။

၃computed ရဲ့ အဓိက ကောင်းချက်က ဘာလဲ။

၄v-model="name" ကို ဖွဲ့ပြရင် ဘယ်လို ဖြစ်လဲ။

၅Child component က ဒေတာ ပြင်ချင်ရင် ဘာလုပ်ရမလဲ။

၆v-for မှာ :key အတွက် အကောင်းဆုံး ရွေးချယ်မှုက ဘယ်ဟာလဲ။

၇Component မပျက်ခင် timer ရပ်ဖို့ ဘယ် hook မှာ ထားမလဲ။

၈Route parameter ကို component ထဲမှာ ဖတ်ဖို့ ဘာသုံးလဲ။

၉fetch မှာ HTTP 404 ကို မှန်ကန်စွာ ကိုင်တွယ်တဲ့ နည်းက ဘယ်ဟာလဲ။

၁၀Quasar မှာ install/offline ပါတဲ့ app ထုတ်ဖို့ ဘယ် command လဲ။

အမှတ် အနည်းအများ

၈၀% အထက် ရရင် Vue အခြေခံ ခိုင်ပြီ။ ၅၀–၇၉% ဆိုရင် မှားတဲ့ အခန်းကို ပြန်ဖတ်ပါ။ ၅၀% အောက် ဆိုရင် အခန်း ၁–၆ (ref, template, event, v-for) ကနေ ပြန်စပါ။ Q&A မေးခွန်း ၁၂ ပုဒ်ကိုလည်း ဆက်ဖြေကြည့်ပါ။