ရိုးရိုးလေး ရှင်းပြမယ်
ref() သည် တန်ဖိုးတစ်ခုကို reactive wrapper ထဲထည့်ပြီး JavaScript တွင် .value ဖြင့်ဖတ်/ရေးရသည်။ reactive() သည် object ကို proxy အဖြစ်ပြောင်းပေးသည်။ Template ထဲတွင် ref ကို .value မလိုဘဲ တိုက်ရိုက်သုံးနိုင်သည်။
vue
<script setup>
import { ref, reactive } from 'vue'
const count = ref(0)
const user = reactive({ name: 'Aye Aye', points: 10 })
function addPoint() {
count.value++
user.points += 5
}
</script>
<template>
<button @click="addPoint">Clicks: {{ count }}</button>
<p>{{ user.name }} — {{ user.points }} points</p>
</template>You should see
Clicks: 1
Aye Aye — 15 pointsလက်တွေ့စမ်းကြည့်ရန်
Shopping cart quantity ကို ref ဖြင့်သိမ်းပြီး +/− button နှစ်ခုဖြင့် ပြောင်းလဲပါ။
Reactivity Fundamentals — Vue.js