Complete the code to create a Pinia store with a state property 'count' initialized to 0.
import { defineStore } from 'pinia'; export const useCounterStore = defineStore('counter', { state: () => ({ count: [1] }) });
The state property 'count' should start at 0 to represent a numeric counter.
Complete the code to commit a mutation in Vuex that increments 'count' by 1.
const store = new Vuex.Store({
state: { count: 0 },
mutations: {
increment(state) {
state.count [1] 1;
}
}
});To increase the count by 1, use the '+=' operator.
Fix the error in the Pinia action that tries to update the state directly without using 'this'.
export const useCounterStore = defineStore('counter', { state: () => ({ count: 0 }), actions: { increment() { [1].count++; } } });
In Pinia actions, use 'this' to access and modify the store's state.
Fill both blanks to define a Vuex getter that returns double the count.
const store = new Vuex.Store({
state: { count: 0 },
getters: {
doubleCount: (state) => state.[1] [2] 2
}
});The getter accesses 'count' and multiplies it by 2 using '*'.
Fill all three blanks to create a Pinia store with a getter that returns count squared.
export const useCounterStore = defineStore('counter', { state: () => ({ count: 0 }), getters: { squaredCount: (state) => state.[1] [2] [3] } });
The getter returns 'count' raised to the power of 2 using the '**' operator.
