data တွေပေါ် အခြေခံပြီး တွက်ထုတ်တဲ့ values — data မပြောင်းမချင်း cache ထားတယ်
computed: {
fullName() {
return this.firstName + ' ' + this.lastName
},
reversedMsg() {
return this.message.split('').reverse().join('')
}
}
Full name: {{ fullName }}
Upper: {{ upperName }}
Length: {{ fullName.length }} characters
Reversed: {{ reversedMsg }}
Computed = cached (data မပြောင်းမချင်း ထပ်မတွက်), Methods = always run
// Computed — cached ✅
computed: {
expensive() { return heavyCalc(this.num) }
}
// Methods — called every render ⚠️
methods: {
expensive() { return heavyCalc(this.num) }
}
Run count: {{ computedCount }}
Value: {{ computedDouble }}
Run count: {{ methodCount }}
Value: {{ methodDouble() }}
computed: {
fullName: {
get() { return this.first + ' ' + this.last },
set(val) {
[this.first, this.last] = val.split(' ')
}
}
}
First: Last:
Full (computed get): {{ fullName }}
Edit full directly (computed set):
data တစ်ခုပြောင်းတာကို ကြည့်ပြီး side effect (API call, log, etc.) လုပ်ဖို့
watch: {
searchTerm(newVal, oldVal) {
console.log('Changed from', oldVal, 'to', newVal)
this.doSearch(newVal) // e.g. fetch API
}
}
Searching for: {{ searchTerm }}
watch: {
// immediate: true → mount ဖြစ်ချင်းတည်း run
count: {
handler(val) { ... },
immediate: true
},
// deep: true → nested object ကို watch လုပ်
user: {
handler(val) { ... },
deep: true
}
}
User name: Age:
Showing {{ filteredUsers.length }} of {{ people.length }} users
No results found.
← Lesson 03 | Next: Lesson 05 → Components