Stan aplikacji
state/pinia-store-to-refs
State and getters taken out of a Pinia store go through storeToRefs(); plain destructuring freezes them at their first value.
poważnastatycznefe-state
Dlaczego
A Pinia store is a reactive object. const { name, total } = useCartStore() copies the current values into plain variables, so the template keeps showing them after the store changes: the cart badge says 0 while the cart fills up. Nothing warns about it.
Poprawka
Use const { name, total } = storeToRefs(store) for state and getters, or read them through the store (cart.total). Actions are bound to the store and may be destructured directly: const { addItem } = cart.
Przykłady
// bad
const { items, total, addItem } = useCartStore()
// good
const cart = useCartStore()
const { items, total } = storeToRefs(cart)
const { addItem } = cartŹródła
Fakty
- Identyfikator
state/pinia-store-to-refs- Waga
- poważna
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
vue- Tylko w projektach z
pinia- Uczy jej skill
fe-stateState and stores- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain state/pinia-store-to-refs