Vue နဲ့ Quasar ကို မြန်မာလို
App ဆောက်တဲ့အထိ
JavaScript အခြေခံ ရှိပြီးသားဆိုရင် Vue က မျက်နှာပြင်ကို ရှင်းရှင်း ရေးနိုင်တဲ့ နည်းလမ်း ဖြစ်တယ်။ Reactivity၊ component၊ router၊ Pinia နဲ့ Quasar layout/components ကို အခန်း ၁၈ ခန်း နဲ့ မေးခွန်း ၂၂ ပုဒ် ထည့်ထားတယ်။
Vue အခြေခံ
Template · Reactivity · Event · v-if/v-for
App တည်ဆောက်မှု
Component · Router · Pinia · Fetch
Quasar နဲ့ ပို့
Components · Layout · Build · PWA
ဒီစာမျက်နှာက ဖတ်ရှုရန် သင်ခန်းစာပါ။ Vue/Quasar က build tool လိုတာမို့ ကုဒ်တွေကို ဒီစာမျက်နှာမှာ run မထားပါဘူး — ကုဒ်တိုင်းရဲ့ အောက်မှာ Expected Output ကို ပြထားတယ်။ လက်တွေ့ စမ်းချင်ရင် Node.js ၂၀+ install ပြီး ကိုယ်ပိုင် project မှာ run ပါ။
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 JS | Vue |
|---|---|---|
| မျက်နှာပြင် ပြင်ဆင် | DOM ကို ကိုယ်တိုင် ရှာ/ပြင် | ဒေတာ ပြောင်းရုံ |
| ကုဒ် ဖွဲ့စည်းပုံ | လုပ်ငန်း ကြီးလာရင် ရှုပ် | Component အလိုက် ခွဲ |
| အခြေအနေ (state) | variable တွေ ကွဲပြား | တစ်နေရာတည်း စုစည်း |
၂။ အသေးဆုံး Vue ဥပမာ
<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>
မင်္ဂလာပါ Vue!
{{ message }} က template ထဲမှာ ဒေတာကို ထည့်တဲ့ နည်း။
message ကို ပြောင်းလိုက်ရင် မျက်နှာပြင်က ချက်ချင်း ပြောင်းတယ်။
ဒီဥပမာက လေ့လာဖို့ပါ — project တကယ်ဆောက်ရင် Vite/Quasar သုံးတယ် (အခန်း ၂၊ ၁၃)။
၃။ SPA နဲ့ Component
- SPA (Single Page Application) — မျက်နှာပြင် တစ်ခုတည်းမှာ route တွေ ပြောင်းတာ၊ page မလှန်ဘဲ ချက်ချင်း ပြည့်တယ်။
- Component — မျက်နှာပြင် အပိုင်းတစ်ခုစီ (navbar၊ ပစ္စည်းကတ်၊ ဇယား) ကို သီးခြား ဖိုင်နဲ့ ရေးတယ်။ ပြန်သုံးလို့ရ၊ စမ်းရ လွယ်တယ်။
- Composition API — Vue 3 ရဲ့ ဒေတာ/လုပ်ဆောင်ချက် စုစည်းရေးတဲ့ ပုံစံ၊
<script setup>နဲ့ ရေးတာ အသုံးများတယ်။
Website တစ်ခုကို LEGO တုံးတွေ တည်ဆောက်သလို မြင်ပါ။ Component တစ်ခုက တုံးတစ်တုံး။ ပစ္စည်းကတ် တုံးကို နေရာ ၁၀ နေရာမှာ သုံးချင်ရင် တစ်ခါရေးပြီး ၁၀ ခါ ခေါ်ရုံပါပဲ။
Setup (Vite / CDN)
Vue project ကို နည်း ၂ မျိုးနဲ့ စနိုင်တယ် — လေ့လာဖို့ CDN (script တစ်ကြောင်း)၊ တကယ့် project အတွက် Vite။ တကယ့် project မှာ Vite ကို သုံးပါ။
ဒီခန်း ပြီးရင် သိလာမယ့် အချက်
- Node.js လိုအပ်ချက်
- create-vue နဲ့ project ဖန်တီးပုံ
- Project ဖွဲ့စည်းပုံ
- Dev server နဲ့ build
၁။ Project ဖန်တီးခြင်း
npm create vue@latest shop-app
cd shop-app
npm install
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.js | App စတင် mount လုပ်တဲ့ နေရာ |
src/App.vue | အပေါ်ဆုံး component |
src/components/ | ပြန်သုံးမယ့် component ငယ်များ |
src/views/ | Route တစ်ခုချင်းစီရဲ့ မျက်နှာပြင် |
src/stores/ | Pinia store (အခန်း ၁၀) |
vite.config.js | Build/dev config |
၃။ Single File Component (SFC)
<script setup>
import { ref } from "vue";
const shopName = ref("NCT လျှပ်စစ်ပစ္စည်း");
</script>
<template>
<h1>{{ shopName }}</h1>
</template>
<style scoped>
h1 { color: #42b883; }
</style>
NCT လျှပ်စစ်ပစ္စည်း (အစိမ်းရောင် ခေါင်းစဉ်)
ဖိုင် တစ်ခုထဲမှာ template (မျက်နှာပြင်)၊ script (ဒေတာ/လုပ်ဆောင်ချက်)၊
style (scoped ဆိုရင် ဒီ component မှာပဲ သက်ရောက်) သုံးပိုင်း ပါတယ်။
HTML ဖိုင် တစ်ခုထဲမှာ Vue ကို စမ်းကြည့်ချင်ရင် CDN က လွယ်တယ်။ ဒါပေမယ့် route၊ component များတဲ့ project အတွက် Vite/Quasar က ပိုသင့်တယ် — hot reload၊ build optimization စတာတွေ ပါတယ်။
Template နဲ့ Data Binding
Vue template က HTML နဲ့ တူတယ် — ထပ်ဆောင်း အနေနဲ့ {{ }} နဲ့
directive (v-bind, v-if စတာတွေ) ပါတယ်။
ဒီခန်းမှာ ဒေတာ ပြခြင်းနဲ့ attribute ချိတ်ခြင်းကို လေ့လာမယ်။
ဒီခန်း ပြီးရင် သိလာမယ့် အချက်
- Interpolation
{{ }} v-bindနဲ့ attribute ချိတ်ခြင်း- Dynamic class နဲ့ style
- Template ထဲမှာ ခေါ်လို့ရတဲ့ expression
၁။ ဒေတာ ပြခြင်း
<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>
မီးသီး 9W ဈေး: 1,500 ကျပ် စုစုပေါင်း: 4500 ကျပ်
{{ }} ထဲမှာ expression ရေးလို့ရတယ် — price * qty၊
name.toUpperCase()။ ဒါပေမယ့် if၊
assignment (x = 1) လို statement မရဘူး။
ရှုပ်တဲ့ တွက်ချက်မှုကို computed မှာ ရေးပါ (အခန်း ၄)။
၂။ v-bind — Attribute ချိတ်ခြင်း
<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>
<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) {} }} |
<script setup> ထဲမှာ name.value
လို့ ရေးရပေမယ့် template မှာ {{ name }} လို့ပဲ ရေးရတယ် —
Vue က အလိုအလျောက် ဖွင့်ပေးတယ်။ Template မှာ name.value
ရေးရင် undefined ရနိုင်တယ်။
Reactivity (ref / reactive / computed)
Reactivity ဆိုတာ ဒေတာ ပြောင်းရင် မျက်နှာပြင် အလိုအလျောက် လိုက်ပြောင်းတဲ့ စနစ်ပါ။
Vue 3 မှာ ref၊ reactive နဲ့
computed က အဓိက တန်ဆာတွေပါ။
ဒီခန်း ပြီးရင် သိလာမယ့် အချက်
refနဲ့ တန်ဖိုး တစ်ခုreactiveနဲ့ objectcomputedရဲ့ cache အာနိသင်- ဘယ်ဟာ ဘယ်အခါ သုံးမလဲ
၁။ ref
<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>
အရေအတွက်: 1
၂။ reactive
<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>
2 × 1500 = 3000 ကျပ်
Object/array ကို တစ်ခုတည်း ကိုင်တွယ်ရင် reactive၊
primitive (number/string/boolean) နဲ့ function ကနေ ပြန်ပေးချင်ရင်
ref ကို သုံးလေ့ရှိတယ်။ နှစ်မျိုးလုံး ရောနိုင်တယ်။
၃။ computed — တွက်ပြီး သိမ်းထား
<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>
Subtotal: 4500 ကျပ် VAT 5%: 225 ကျပ် စုစုပေါင်း: 4725 ကျပ်
computed က မှီခိုတဲ့ တန်ဖိုး မပြောင်းသရွေ့ ပြန်မတွက်ဘူး (cache)။
Method ကို template မှာ ခေါ်ရင် render တိုင်း ပြန်တွက်တာမို့
တွက်ရ လေးတဲ့ အလုပ်အတွက် computed က ပိုကောင်းတယ်။
ခေတ္တ တန်ဖိုး တစ်ခု → ref။
ဆက်စပ် ဒေတာ အုပ်စု → reactive။
အခြား ဒေတာကနေ ဆင်းသက်တဲ့ တန်ဖိုး → computed။
ဒေတာ ပြောင်းတဲ့ အချိန် ဘေးထွက် အလုပ် (API ခေါ်၊ localStorage သိမ်း) → watch (အခန်း ၈)။
Event နဲ့ v-model
Button နှိပ်တာ၊ input ရိုက်တာ — user ရဲ့ လုပ်ဆောင်ချက် တိုင်းက event ပါ။
@click နဲ့ ဖမ်းပြီး v-model နဲ့
ဖောင် တန်ဖိုးကို ဒေတာနဲ့ တိုက်ရိုက် ချိတ်တယ်။
ဒီခန်း ပြီးရင် သိလာမယ့် အချက်
v-on/@နဲ့ event ဖမ်းခြင်းv-modelနဲ့ form ချိတ်ခြင်း- Event modifier (
.prevent,.stop) - ဖောင် တန်ဖိုး ပြောင်းတာကို စောင့်ကြည့်ခြင်း
၁။ Event ဖမ်းခြင်း
<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>
မောင် 3 true
v-model က နှစ်လမ်းသွား ချိတ်ဆက်တယ် —
input ရိုက်ရင် ဒေတာ ပြောင်း၊ ဒေတာ ပြောင်းရင် input ပြောင်း။
.trim က ကြားကွက် ဖြတ်၊ .number က
စာသားကို နံပါတ် အဖြစ် ပြောင်းပေးတယ်။
၂။ Event Modifier
| Modifier | အလုပ် | ဥပမာ |
|---|---|---|
.prevent | Default အလုပ် ပိတ် | @submit.prevent="save" |
.stop | Event ဆက်ပျံ့တာ ရပ် | @click.stop |
.self | ကိုယ့် element ပဲ ဖြစ်မှ | @click.self |
.once | တစ်ခါပဲ လုပ် | @click.once |
၃။ Form နဲ့ ဆက်စပ် သတိထားချက်
Form ကို submit လုပ်ရင် page ပြန်လှန်တာ (refresh) မဖြစ်စေချင်ရင်
@submit.prevent="save" သုံးပါ။
button ကို type="submit" ထားပြီး
form ရဲ့ submit event မှာ ကိုင်တာက နည်းစနစ်ကျတယ် — Enter နှိပ်လည်း အလုပ်လုပ်တယ်။
v-model ကို checkbox မှာ သုံးရင် တန်ဖိုးက
true/false ဖြစ်တယ်။
ref("") နဲ့ စထားရင် initial state မှာ
“မှား” မဟုတ်ဘဲ ဗလာစာသား ဖြစ်နေတတ်တာမို့ ref(false) နဲ့ စပါ။
v-if / v-for
ဒေတာ အခြေအနေ အလိုက် ပြရ/ဖျောက်ရ လိုတယ်။ စာရင်း တစ်ခုကို ထပ်ပြီး
ပြရ လိုတယ်။ ဒါတွေကို v-if နဲ့
v-for က လုပ်ပေးတယ်။
ဒီခန်း ပြီးရင် သိလာမယ့် အချက်
v-if/v-else-if/v-elsev-showနဲ့ ကွာခြားချက်v-forနဲ့:key- စာရင်း ပြတဲ့အခါ ဖြစ်တတ်တဲ့ ပြဿနာ
၁။ v-if နဲ့ v-show
<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>
ကုန်နေပြီ ⚠ ပြန်မှာယူပါ
| Directive | ဘယ်လို လုပ် | ဘယ်အခါ သုံး |
|---|---|---|
v-if | DOM ကို ဖျက်/ပြန်ဆောက် | ပြောင်းတာ ရှားတဲ့ အခါ |
v-show | CSS display:none ပဲ | မကြာခဏ ပြောင်းတဲ့ အခါ |
၂။ v-for နဲ့ စာရင်း ပြခြင်း
<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>
မီးသီး — 1,500 ကျပ် ပလပ်စွပ် — 800 ကျပ် ကြိုး — 3,200 ကျပ်
:key က Vue ကို ဘယ် item က ဘယ်ဟာလဲ ခွဲသိစေတယ်။
Unique ဖြစ်တဲ့ id ကို သုံးပါ — index ကို key အဖြစ် သုံးရင်
စာရင်း အလယ်က ဖျက်/ထည့်တဲ့အခါ မျက်နှာပြင် မှားနိုင်တယ်။
၃။ စာရင်း ထဲက ကို ဖြတ်ပြီး စစ်ခြင်း
<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 က “ဘာမှ မပြတာ” နဲ့ “မတွေ့တာ” ကို ခွဲသိဖို့ လိုတယ်။
Vue 3 မှာ v-if က v-for ထက်
အရင် အလုပ်လုပ်တာမို့ item variable ကို v-if မှာ သုံးလို့ မရဘူး။
လိုအပ်ရင် စစ်ပြီးသား စာရင်းကို computed နဲ့ ပြင်ပြီးမှ
v-for ပါ။
Component (props / emit)
Component က မျက်နှာပြင် အပိုင်း တစ်ပိုင်းကို သီးခြား ဖိုင်နဲ့ ရေးတာပါ။
အပြင်က ဒေတာ ပေးပို့တာက props၊
အတွင်းက အပြင်ကို အသိပေးတာက emit ပါ။
ဒီခန်း ပြီးရင် သိလာမယ့် အချက်
- Component ဖန်တီး/ခေါ်သုံးပုံ
definePropsနဲ့ ဒေတာ လက်ခံခြင်းdefineEmitsနဲ့ event ပို့ခြင်း- Slot နဲ့ အကြောင်းအရာ ထည့်ခြင်း
၁။ Component တစ်ခု ရေးခြင်း
<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 မှာ ခေါ်သုံးခြင်း
<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>
ထည့်ပြီး: မီးသီး, ကြိုး
Static တန်ဖိုးကို name="မီးသီး" လို ရိုးရိုး ရေးနိုင်တယ်။
Number/Boolean/variable ကို ပို့ရင် :price="1500" လို
: ထည့်ရတယ်။ မထည့်ရင် စာသား "1500" ဖြစ်သွားတယ်။
၃။ Slot
<template>
<div class="box">
<slot>အကြောင်းအရာ မထည့်ရင် ဒါ ပေါ်မယ်</slot>
</div>
</template>
Slot က Component ကို “ဘောင်” အဖြစ် သုံးပြီး အတွင်းထည့်တဲ့ အကြောင်းအရာကို ပြောင်းလို့ရတယ်။ Modal၊ Card၊ Alert စတဲ့ ပုံစံ တူတဲ့ အပိုင်းတွေအတွက် အသုံးဝင်တယ်။
Child ထဲမှာ props.price = 2000 လို ပြင်တာ
error ပြတယ် (one-way data flow)။ ပြင်ချင်ရင် emit နဲ့
မိခင်ကို အသိပေးပြီး မိခင်က ပြင်ရတယ်။ ဒါက ဒေတာ စီးဆင်းမှုကို ရှင်းစေတယ်။
Lifecycle နဲ့ watch
Component တစ်ခုက စတင် ပေါ်လာတဲ့အခါ၊ ပျက်သွားတဲ့အခါ လုပ်ရမယ့် အလုပ် ရှိတယ် — API ခေါ်တာ၊ timer ရပ်တာ။ Lifecycle hook တွေက အဲဒီ အချိန်တွေမှာ ဝင်လုပ်ခွင့်ပေးတယ်။
ဒီခန်း ပြီးရင် သိလာမယ့် အချက်
onMounted/onUnmountedwatchနဲ့watchEffect- ဘယ်အလုပ်ကို ဘယ် hook မှာ ထားမလဲ
- Memory leak မဖြစ်အောင် ရှင်းလင်းခြင်း
၁။ Mount နဲ့ Unmount
<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>
2:31:05 PM
၂။ watch
<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>
ပြောင်း: → မ ပြောင်း: မ → မော
watch က ဒေတာ ပြောင်းတာကို စောင့်ကြည့်ပြီး
ဘေးထွက် အလုပ် လုပ်တယ်။ watchEffect ကတော့
အတွင်းက ဖတ်ထားတဲ့ ဒေတာကို အလိုအလျောက် လိုက်ကြည့်တယ် —
ရှင်းရှင်း သိထားတဲ့ အခြေအနေ ရှိရင် watch က ပိုထိန်းချုပ်ရလွယ်တယ်။
| လုပ်ချင်တာ | သုံးရမယ့် နည်း |
|---|---|
| Component ပေါ်ပြီးမှ API ခေါ် | onMounted |
| Component မပျက်ခင်မှာ timer/event ရှင်း | onUnmounted |
| ဒေတာ ပြောင်းတိုင်း သိမ်း/ခေါ် | watch |
| ဒေတာကနေ ဆင်းသက်တဲ့ တန်ဖိုး | computed |
Component ပေါ်တာနဲ့ တစ်ခါ ခေါ်ချင်ရင် onMounted မှာ ထားပါ။
Filter ပြောင်းတိုင်း ပြန်ခေါ်ချင်ရင် watch မှာ ထားပါ။
တစ်ခါတည်း နှစ်နေရာ ခေါ်မိရင် request နှစ်ခါ ထွက်တာမို့ သတိထားပါ။
Vue Router
SPA မှာ page တွေ မလှန်ဘဲ URL အလိုက် မျက်နှာပြင် ပြောင်းတာကို
Vue Router က လုပ်ပေးတယ်။ /products/3 လို
URL တစ်ခုစီမှာ မတူတဲ့ မျက်နှာပြင် ပြနိုင်တယ်။
ဒီခန်း ပြီးရင် သိလာမယ့် အချက်
- Route သတ်မှတ်ပုံ
RouterLink/RouterView- URL parameter ဖတ်ပုံ
- Programmatic navigation
၁။ Route သတ်မှတ်ခြင်း
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;
၂။ ချိတ်ဆက်ခြင်းနဲ့ ပြသခြင်း
<template>
<nav>
<RouterLink to="/">ပင်မ</RouterLink>
<RouterLink to="/products">ပစ္စည်းများ</RouterLink>
</nav>
<RouterView />
</template>
၃။ URL parameter ဖတ်ခြင်း
<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>
ပစ္စည်း ID: 3
Link အတွက် <RouterLink> ကို သုံးပါ —
<a href> က page ကို အပြည့် ပြန်တင်တာမို့ SPA ရဲ့
ကောင်းချက် ပျောက်တယ်။ Code ကနေ ပြောင်းချင်ရင် router.push() သုံးပါ။
route.params.id က string ဖြစ်တယ်။
နံပါတ်နဲ့ နှိုင်းယှဉ်ရင် Number(route.params.id) === 3
လို့ ပြောင်းပါ။ မပြောင်းရင် "3" === 3 က false ဖြစ်တယ်။
Pinia (State Management)
Component တွေ အများကြီး ရှိလာရင် ဒေတာကို မိခင်-သားစဉ် props နဲ့ သာ ပို့နေရင် ရှုပ်တယ်။ Pinia store က ဒေတာကို တစ်နေရာတည်းမှာ သိမ်းပြီး ဘယ် component ကမဆို ယူသုံးလို့ ရစေတယ်။
ဒီခန်း ပြီးရင် သိလာမယ့် အချက်
- Store ဖန်တီးပုံ
state/getters/actions- Component ထဲမှာ ယူသုံးပုံ
- Store ကို ဘယ်အခါ လိုအပ်လဲ
၁။ Store ဖန်တီးခြင်း
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 ထဲမှာ သုံးခြင်း
<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>
ပစ္စည်း: 1 မျိုး စုစုပေါင်း: 1500 ကျပ်
Store ကို main.js မှာ app.use(createPinia())
တစ်ခါ ထည့်ထားဖို့ လိုတယ်။ Store ထဲက state ကို တိုက်ရိုက် ပြင်တာထက်
action ကတစ်ဆင့် ပြင်တာက စည်းကမ်းရှိတယ် —
ဘယ် အလုပ်တွေ လုပ်လဲ ကြည့်ရ လွယ်တယ်။
ဒေတာကို component အနည်းငယ်ပဲ သုံးရင် props/emit က လုံလောက်တယ်။ မျက်နှာပြင် များစွာက ဒေတာ တစ်ခုတည်းကို ကြည့်ရ/ပြင်ရ (login user၊ cart၊ theme) ဖြစ်လာရင် Pinia က ပိုသင့်တယ်။
Fetch API နဲ့ Loading / Error
တကယ့် app တွေက ဒေတာကို server/API ကနေ ယူတယ်။ ဒေတာ မရောက်သေးတဲ့ အချိန်၊ မရတဲ့ အချိန် ကို user ကို ပြဖို့ လိုတယ်။ ဒီခန်းမှာ သုံးမျိုး အခြေအနေ (loading / error / data) ကို စီမံတာ လေ့လာမယ်။
ဒီခန်း ပြီးရင် သိလာမယ့် အချက်
fetchကို async/await နဲ့ ခေါ်ပုံ- Loading/Error/Data အခြေအနေ ခွဲပြပုံ
- API endpoint ကို env variable နဲ့ ထားပုံ
- Error ကို user ကို ဘယ်လို ပြမလဲ
၁။ fetch နဲ့ ဒေတာ ယူခြင်း
<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>
① ခဏစောင့်ပါ... ② ဒေတာ ယူမရပါ — ထပ်စမ်းပါ (HTTP 500 ဖြစ်ရင်) ③ • မီးသီး • ပလပ်စွပ် (အောင်မြင်ရင်)
fetch က HTTP 404/500 မှာ error မပစ်ဘူး —
res.ok ကို ကိုယ်တိုင် စစ်ရတယ်။
Status မစစ်ရင် error page ရဲ့ HTML ကို JSON လို့ ဖတ်မိတာ ဖြစ်တတ်တယ်။
၂။ POST ပို့ခြင်း
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 ကို
လွယ်လွယ် ပြောင်းနိုင်တယ်။
API က id မပေးရင် :key မှာ
p.name သုံးရတတ်တယ်။ နာမည် ထပ်နေရင်တော့ key ထပ်ပြီး
render မှားတယ်။ API ဒီဇိုင်း ရွေးချယ်တဲ့အခါ id တစ်ခု ပါအောင် သတ်မှတ်ထားတာ အကောင်းဆုံးပါ။
Build နဲ့ Deploy
ရေးထားတဲ့ .vue ဖိုင်တွေကို browser က တိုက်ရိုက် မဖတ်နိုင်ဘူး။
Build လုပ်တဲ့အခါ HTML/CSS/JS ဖိုင်တွေ အဖြစ် ပြောင်းပြီး
dist/ ဖိုဒါထဲ ထည့်ပေးတယ်။ အဲဒါကို hosting မှာ တင်ရတယ်။
ဒီခန်း ပြီးရင် သိလာမယ့် အချက်
npm run buildက ဘာ လုပ်လဲ- Build ရလဒ်ကို စမ်းကြည့်ပုံ
- Static hosting မှာ တင်ပုံ
- Subfolder မှာ တင်ရင် ဖြစ်တတ်တဲ့ ပြဿနာ
၁။ Build လုပ်ခြင်း
npm run build
npm run preview
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 / Vercel | Git repo ချိတ်၊ build command npm run build၊ output dist | အလွယ်ဆုံး |
| GitHub Pages | dist ကို gh-pages branch သို့ တင် | Subfolder URL အတွက် base သတ်မှတ်ရ |
| ကိုယ်ပိုင် server | dist ကို web root မှာ ကော်ပီ | History mode အတွက် fallback လိုအပ် |
createWebHistory() သုံးထားရင် /products
ကို တိုက်ရိုက် ဖွင့်တဲ့အခါ server မှာ ဖိုင် မရှိတာမို့ 404 ပြတယ်။
SPA hosting ရဲ့ “redirect all to index.html” setting ကို ဖွင့်ပါ
(Netlify မှာ _redirects ဖိုင်၊ Vercel မှာ rewrites)။
Quasar မိတ်ဆက်
Quasar က Vue 3 အတွက် UI component တွေ အသင့် ပေးထားတဲ့ framework ပါ။ ဒီတစ်ခုတည်းနဲ့ website၊ PWA၊ Android/iOS app၊ desktop app ကို code တစ်စုတည်းကနေ ထုတ်နိုင်တယ်။
ဒီခန်း ပြီးရင် သိလာမယ့် အချက်
- Quasar က ဘာအတွက် ကောင်းလဲ
- Project ဖန်တီး/run ပုံ
- ဖိုဒါ တည်ဆောက်ပုံ
- Vue ချည်းသက်သက်နဲ့ ကွာခြားချက်
၁။ Project ဖန်တီးခြင်း
npm init quasar
cd shop-app
npm install
quasar dev
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.js | Route စာရင်း |
quasar.config.js | Build၊ plugin၊ boot ဖိုင် သတ်မှတ်ချက် |
src/boot/ | App မစခင် run မယ့် ကုဒ် |
Button၊ Table၊ Dialog၊ Date picker စတဲ့ UI ကို ကိုယ်တိုင် CSS ရေးစရာ မလိုဘဲ ရနိုင်တယ်။ ဖုန်း၊ တက်ဘလက်၊ desktop အတွက် အလိုအလျောက် လိုက်လျောညီထွေ ဖြစ်တယ်။ ဒါပေမယ့် app ကို Quasar ရဲ့ စည်းကမ်းနဲ့ လိုက်ရတာမို့ ရိုးရိုး Vue ထက် အလေ့အကျင့် နည်းနည်း ပိုလိုတယ်။
Quasar Components
q-btn၊ q-input၊
q-table၊ q-dialog တွေက
Quasar ရဲ့ အသုံးအများဆုံး component တွေပါ။
ဒီခန်း ပြီးရင် သိလာမယ့် အချက်
q-inputနဲ့ validationq-tableနဲ့ စာရင်း ပြခြင်းq-dialogနဲ့ Notify- အရောင်/ပုံစံ ပြောင်းပုံ
၁။ Form နဲ့ validation
<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>
ပစ္စည်း အမည် [ နာမည် ထည့်ပါ ] ← input အောက်မှာ အနီရောင် ပြ
rules က true ပြန်ရင် အောင်မြင်၊ string ပြန်ရင်
အဲဒီ စာသားကို error အဖြစ် ပြတယ်။ Form တစ်ခုလုံး စစ်ချင်ရင်
q-form နဲ့ ခြုံပြီး validate() ခေါ်တာ ပိုရှင်းတယ်။
၂။ Table
<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
<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>
[ ဖျက်မလား? ] → “ဖျက်မည်” နှိပ်ရင် ညာဘက်အောက် အနီရောင် toast: ဖျက်ပြီးပါပြီ
$q.notify မပေါ်ရင် quasar.config.js
ရဲ့ framework.plugins မှာ "Notify"
ထည့်ထားခြင်း မရှိလို့ ဖြစ်နိုင်တယ်။ ဒါကို မေ့ရင် error မပြတဲ့ဘဲ toast ပျောက်နေတယ်။
Layout (Header / Drawer / Page)
မျက်နှာပြင် တိုင်းမှာ ထိပ်ဘား နဲ့ ဘေး မီနူး ရှိတယ်။ Layout ကို တစ်ခါ ရေးပြီး page တွေ အားလုံး အဲဒီထဲ ထည့်တာမို့ ထပ် မရေးရတော့ဘူး။
ဒီခန်း ပြီးရင် သိလာမယ့် အချက်
q-layoutရဲ့ အစိတ်အပိုင်းများ- Drawer ကို ဖုန်းမှာ ဖျောက်ခြင်း
- Screen size အလိုက် ပြောင်းခြင်း
- Dark mode
၁။ Layout အခြေခံ
<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
<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.md | md ထက် သေးတယ် (ဖုန်း) |
$q.screen.gt.sm | sm ထက် ကြီးတယ် (desktop) |
$q.dark.toggle() | Dark/Light လှည့် |
Page တိုင်းမှာ q-layout ထပ်ရေးရင် ထိပ်ဘား
တစ်ခါ၊ ကျောက်တစ်ခါ လှုပ်နိုင်တယ်။ Layout ကို src/layouts/
မှာ တစ်ခုတည်း ထားပြီး routes မှာ component: MainLayout
နဲ့ ခြုံပါ။
Build / PWA / Mobile App
Quasar မှာ ထုတ်ချင်တဲ့ ပုံစံကို -m နဲ့ ရွေးတယ်။
တူညီတဲ့ code ကနေ website၊ install လုပ်လို့ရတဲ့ PWA၊ Android/iOS app ကို ထုတ်နိုင်တယ်။
ဒီခန်း ပြီးရင် သိလာမယ့် အချက်
- SPA / PWA / Capacitor / Electron ကွာခြားချက်
- Build command နဲ့ ရလဒ် ဖိုဒါ
- PWA အတွက် လိုအပ်ချက်
- ဘယ်ဟာကို ဘယ်အခါ ရွေးမလဲ
၁။ Mode ရွေးခြင်း
quasar build -m spa
quasar build -m pwa
quasar build -m capacitor -T android
Build succeeded dist/spa/index.html dist/spa/assets/app-4b7c9d.js
| Mode | ရလဒ် | သုံးရမယ့် အခြေအနေ |
|---|---|---|
| SPA | Static ဖိုင်များ | Netlify/Vercel မှာ website |
| PWA | Install လုပ်နိုင်၊ offline ဖတ်နိုင် | ဖုန်းမှာ browser ကနေ install စေချင် |
| Capacitor | Android/iOS project | Play Store/App Store မှာ တင်ချင် |
| Electron | Windows/Mac/Linux app | Desktop မှာ ထည့်သွင်းချင် |
၂။ PWA ဖြစ်ဖို့
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 မှန်ရင် ချက်ချင်း ရနိုင်တယ်။
Capacitor mode မှာ npx cap add android ပြီး
Android Studio နဲ့ ဖွင့်တယ်။ တကယ် ဖုန်းမှာ စမ်းဖို့ USB debugging လိုတယ်။
Store မှာ တင်ရင် signing key နဲ့ privacy policy လိုတာမို့ ဒီအဆင့်ကို
ကိုယ်ပိုင် lab မှာ သာစမ်းပါ။
မေးခွန်း ၁၂ ဖြေကြည့်ပြီး အဖြေ ဖွင့်ကြည့်ပါ
အခန်း ၁–၁၆ ကို အခြေခံထားတဲ့ မေးခွန်း ၁၂ ပုဒ်ပါ။ ကိုယ်တိုင် အဖြေ စဉ်းစားပြီးမှ ကလစ်ပြီး ဖွင့်ကြည့်ပါ။ မှားတဲ့ မေးခွန်းရဲ့ “ပြန်ဖတ်” လင့်ခ်ကို နှိပ်ပြီး အခန်းကို ပြန်ဖတ်ပါ။
Code ဥပမာတွေကို ကိုယ်ပိုင် project မှာ ရိုက်ထည့်ပြီး browser မှာ ပြောင်းကြည့်ပါ။ Vue မှာ “ဘာကြောင့် ဒီလို ရလဲ” ကို ရှင်းနိုင်ရင် အသိခိုင်ပြီ။
Vue အခြေခံ
၁။ Vue ကို CDN နဲ့ သုံးတာနဲ့ Vite project နဲ့ သုံးတာ ဘာကွာလဲ။
.vue ဖိုင်၊ component၊ router၊ build လုပ်တာတွေ ပါတာမို့ project တကယ် ဆောက်ရင် Vite သုံးတယ်။အခန်း ၂ · Setup ပြန်ဖတ်၂။ ref နဲ့ reactive က ဘာကွာလဲ။
reactive က object/array ပဲ လက်ခံပြီး property ကို တိုက်ရိုက် ဖတ်တယ်။ ရိုးရှင်းတဲ့ တန်ဖိုး တစ်ခုတည်း အတွက် ref က ပိုသင့်တယ်။အခန်း ၄ · Reactivity ပြန်ဖတ်၃။ Template ထဲမှာ {{ count }} လို့ ရေးရင် .value မလိုဘူးလား။
<script setup> က ပြင်ဆင်ထားတဲ့ ref ကို template မှာ unwrap လုပ်ပေးတယ်။ count.value လို့ ရေးရင်တော့ မှားတယ် (template မှာ value က မရှိ)။ Script ထဲမှာတော့ count.value ပဲ။အခန်း ၃ · Template ပြန်ဖတ်၄။ computed ကို ဘာကြောင့် သုံးလဲ။ method နဲ့ မတူဘူးလား။
computed က မှီခိုတဲ့ ဒေတာ ပြောင်းမှ ပြန်တွက်တယ်။အခန်း ၄ · Reactivity ပြန်ဖတ်၅။ v-model.trim နဲ့ v-model.number က ဘာလုပ်လဲ။
.number မထည့်ရင် "3" + 1 က "31" ဖြစ်တယ်။ နာမည်/ရှာချက် မှာ .trim က မလိုချင်တဲ့ ကွက်လပ် ဖြတ်တယ်။အခန်း ၅ · Event ပြန်ဖတ်Component နဲ့ Router
၆။ Child component က props ကို ပြင်လို့ ရလား။
defineEmits နဲ့ event ပို့ပြီး ပိုင်ရှင် component က state ကို ပြင်ရတယ်။အခန်း ၇ · Component ပြန်ဖတ်၇။ v-for မှာ :key က ဘာကြောင့် လိုတာလဲ။
၈။ Component ပေါ်တာနဲ့ API ခေါ်ချင်ရင် ဘယ် hook မှာ ထားမလဲ။
onMounted က DOM ပေါ်ပြီးမှ run တာမို့ ဒေတာ ပြဖို့ အသင့် ဖြစ်တယ်။ Timer/event ထည့်ထားရင် onUnmounted မှာ ရှင်းဖို့ မမေ့ပါနဲ့။အခန်း ၈ · Lifecycle ပြန်ဖတ်၉။ route.params.id နဲ့ နံပါတ် နှိုင်းယှဉ်တာ ဘာကြောင့် မမှန်တာလဲ။
"3" === 3 က false ဖြစ်တယ်။ Number(route.params.id) === 3 လို ပြောင်းပြီးမှ နှိုင်းယှဉ်ပါ။အခန်း ၉ · Router ပြန်ဖတ်State, API နဲ့ Quasar
၁၀။ 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 ကွာခြားချက်က ဘာလဲ။
dist/spa ကို hosting မှာ တင်တယ်။ PWA က manifest + service worker ပါတာမို့ ဖုန်း မျက်နှာပြင်မှာ install လုပ်နိုင်၊ offline ဖတ်နိုင်တယ်။ HTTPS လိုတယ်။အခန်း ၁၆ · Build ပြန်ဖတ်
npm create vue@latest နဲ့ project တစ်ခု ဖန်တီးပြီး
ပစ္စည်း စာရင်း + cart + router ၃ မျက်နှာပြင် လုပ်ကြည့်ပါ။ ပြီးရင် Quasar project
နဲ့ အလားတူ app ကို ပြန်ဆောက်ကြည့်ပါ — နှစ်ခု ကွာခြားချက်ကို ကိုယ်တွေ့ သိလာမယ်။
ရွေးချယ်မေးခွန်း ၁၀ အမှတ် တွက်ကြည့်ပါ
မေးခွန်း တစ်ခုစီမှာ က) ခ) ဂ) ဃ) ထဲက မှန်တဲ့ အဖြေ တစ်ခုကို ရွေးပါ။ အားလုံး ရွေးပြီးရင် “အဖြေစစ်မယ်” ကို နှိပ်ပြီး အမှတ် ကြည့်ပါ။ မှားတဲ့ မေးခွန်းမှာ မှန်တဲ့အဖြေကို အစိမ်းရောင်၊ ကိုယ်ရွေးလိုက်တဲ့ အမှားကို အနီရောင် ပြပေးပါတယ်။
၁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 မေးခွန်း ၁၂ ပုဒ်ကိုလည်း ဆက်ဖြေကြည့်ပါ။