Vue · Junior · Question 49 of 75
How is a Pinia store defined and used?
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();- ✓Correct answer: With
defineStore; refs become state, computed become getters and functions become actions - 2With
new Store()inmain.jsandthis.$storein components - 3With a global
reactiveobject exported from a file - Pinia has no API
Explanation
This is a setup store; there are also option stores with state, getters and actions. The store is created on first use and shared across components.