ရိုးရိုးလေး ရှင်းပြမယ်
Local component state ကို အလွယ်တကူမရွှေ့ပါနှင့်။ User session, cart သို့မဟုတ် app-wide filters ကဲ့သို့ component များစွာမျှဝေသည့် state အတွက် Pinia သုံးပါ။ State ကို function ဖြင့်ကြေညာပြီး derived state ကို getters, changes ကို actions အဖြစ်ရေးပါ။
javascript
import { defineStore } from 'pinia'
export const useCartStore = defineStore('cart', {
state: () => ({ items: [] }),
getters: {
totalItems: (state) => state.items.length
},
actions: {
add(product) {
this.items.push(product)
}
}
})You should see
cart.totalItems = 0လက်တွေ့စမ်းကြည့်ရန်
User preferences အတွက် theme နှင့် locale state ပါသော Pinia store တစ်ခုတည်ဆောက်ပါ။
Pinia State — Pinia