Vue · Junior · Pytanie 49 z 75
Jak definiuje się i używa store'a Pinia?
export const useCounterStore = defineStore("counter", () => {
const count = ref(0);
const double = computed(() => count.value * 2);
function increment() { count.value++; }
return { count, double, increment };
});
// in a component: const counter = useCounterStore();- ✓Poprawna odpowiedź: Przez
defineStore; refy stają się stanem, computed - getterami, a funkcje - akcjami - 2Przez
new Store()wmain.jsithis.$storew komponentach - 3Globalnym obiektem
reactiveeksportowanym z pliku - Pinia nie ma API
Wyjaśnienie
To setup store; są też option store'y ze state, getters i actions. Store jest tworzony przy pierwszym użyciu i współdzielony przez komponenty.