CHAPTER 17
Beginner
Vuex Fundamentals
Updated: May 18, 2026
5 min read
# CHAPTER 17
Vuex Fundamentals
1. Chapter Introduction
Vuex was the original official state management library for Vue. While Pinia is the modern standard for new Vue 3 projects, Vuex remains widely used in Vue 2 codebases and older Vue 3 projects. Understanding Vuex is essential for maintaining legacy code and interviews.2. Learning Objectives
- Understand Vuex core concepts: state, mutations, actions, getters.
- Use Vuex in a Vue 3 project.
- Understand why Vuex requires mutations.
- Compare Vuex and Pinia.
- Organize large stores with modules.
3. Vuex vs Pinia Comparison
text
4. Setting Up Vuex
bash
javascript
main.js
5. Using Vuex in Components
vue
6. Vuex Modules
javascript
7. Common Mistakes
-
Directly mutating state:
store.state.count++bypasses Vuex's tracking and breaks DevTools. Always use mutations.
- Async code in mutations: Mutations must be synchronous. Use actions for API calls.
8. MCQs
Question 1
Only way to change Vuex state?
Question 2
Mutations must be?
Question 3
Actions are called via?
Question 4
store.getters.cartTotal is like?
Question 5
Vuex modules use namespaced: true for?
Question 6
useStore() in Composition API?
Question 7
Why Vuex requires mutations (not direct state mutation)?
Question 8
Getters with params (parameterized)?
Question 9
Accessing namespaced action?
Question 10
Pinia over Vuex for new projects because?
9. Interview Questions
- Q: Why does Vuex require mutations for state changes instead of allowing direct mutations?
- Q: What is the difference between mutations and actions in Vuex?