The store's count starts at 0 as defined in state.
Step 2: Analyze increment action
The increment method increases count by 1 using this.count++.
Step 3: Check the output after calling increment
After calling store.increment(), count becomes 1.
Final Answer:
1 -> Option C
Quick Check:
Increment increases count to 1 [OK]
Hint: Actions modify state directly in Pinia [OK]
Common Mistakes:
Expecting count to remain 0
Confusing actions with mutations
Assuming increment is undefined
4. Identify the error in this Vuex store mutation and how to fix it:
const store = new Vuex.Store({
state: { count: 0 },
mutations: {
increment(state) {
state.count++
}
}
})
store.increment()
medium
A. Mutations must be called with commit, so use store.commit('increment') instead of store.increment()
B. State should be a function returning an object, not an object directly
C. Mutations cannot modify state directly, use actions instead
D. The mutation name must be uppercase
Solution
Step 1: Check how mutations are called in Vuex
Vuex mutations must be triggered using store.commit('mutationName'), not by calling the mutation function directly.
Step 2: Identify the fix
Replace store.increment() with store.commit('increment') to correctly invoke the mutation.
Final Answer:
Mutations must be called with commit, so use store.commit('increment') instead of store.increment() -> Option A
Quick Check:
Vuex mutations require commit() [OK]
Hint: Use commit() to call Vuex mutations [OK]
Common Mistakes:
Calling mutation functions directly
Thinking state must be a function in Vuex root store
Believing mutations can't modify state
5. You want to migrate a Vuex store to Pinia. Which of these changes is necessary to adapt the Vuex mutation increment(state) { state.count++ } into Pinia's style?
hard
A. Keep the mutation as is and call it with store.commit('increment') in Pinia.
B. Convert the mutation into an action method that directly modifies state using this.count++.
C. Remove the mutation and update state only via getters.
D. Use store.dispatch('increment') to call the mutation in Pinia.
Solution
Step 1: Understand Vuex mutation role
Vuex mutations modify state and are called via commits.
Step 2: Understand Pinia's approach
Pinia does not use mutations; instead, actions directly modify state using this.
Step 3: Adapt mutation to Pinia action
Convert the mutation into an action method that increments this.count directly.
Final Answer:
Convert the mutation into an action method that directly modifies state using this.count++. -> Option B
Quick Check:
Pinia uses actions, no mutations [OK]
Hint: Pinia replaces mutations with direct state changes in actions [OK]
Common Mistakes:
Trying to use commit() in Pinia
Using getters to update state
Calling dispatch() for mutations in Pinia
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.