Challenge - 5 Problems
Pinia vs Vuex Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Key difference in store setup between Pinia and Vuex
Which statement correctly describes how you create a store in Pinia compared to Vuex?
Attempts:
2 left
💡 Hint
Think about how you define state and actions in each library.
✗ Incorrect
Pinia uses a function called defineStore to create stores, which returns reactive state and actions. Vuex uses an object with separate mutations and actions properties.
❓ component_behavior
intermediate2:00remaining
State reactivity difference in Pinia vs Vuex
What happens when you update a state property in Pinia compared to Vuex in a Vue component?
Attempts:
2 left
💡 Hint
Consider how each library handles state changes and reactivity.
✗ Incorrect
Pinia allows direct state modification and Vue tracks changes reactively. Vuex requires committing mutations to update state reactively.
📝 Syntax
advanced2:30remaining
Correct syntax for defining a Pinia store
Which code snippet correctly defines a Pinia store with a state property 'count' initialized to 0 and an action 'increment' that increases count by 1?
Attempts:
2 left
💡 Hint
Check the correct function and object structure for Pinia stores.
✗ Incorrect
Option A uses defineStore with an id string and an object containing state as a function returning an object, and actions as methods. This matches Pinia's syntax.
🔧 Debug
advanced2:00remaining
Identify the error in Vuex mutation usage
Given this Vuex mutation code, what error will occur when committing 'increment' mutation?
const store = new Vuex.Store({
state: { count: 0 },
mutations: {
increment(state) {
state.count += 1
}
}
});
store.commit('increment');
console.log(store.state.count);
Attempts:
2 left
💡 Hint
Check how Vuex mutations receive state and how commit works.
✗ Incorrect
The mutation function receives the state as first argument and can modify it directly. Committing 'increment' increases count by 1. No error occurs.
❓ state_output
expert2:30remaining
Pinia store state after multiple actions
Consider this Pinia store and usage:
import { defineStore } from 'pinia';
export const useStore = defineStore('main', {
state: () => ({ value: 10 }),
actions: {
add(n) {
this.value += n;
},
reset() {
this.value = 0;
}
}
});
const store = useStore();
store.add(5);
store.add(-3);
store.reset();
store.add(7);
What is the final value of store.value?
Attempts:
2 left
💡 Hint
Follow each action step by step and update the value.
✗ Incorrect
Starting at 10, add(5) makes 15, add(-3) makes 12, reset() sets to 0, add(7) makes 7.