Pinia offers simpler API without mutations, better TypeScript support, multiple stores without modules, automatic code splitting. More lightweight and intuitive than Vuex.
In Vuex: use mapState helper or $store.state. In Pinia: use store instance directly or storeToRefs. Both support computed properties for reactivity.
Getters compute derived state. Access other getters and state. Cache results based on dependencies. Similar to computed properties for stores.
Modules split store into sub-stores. Support namespacing. Handle state separation. Implement module registration. Support dynamic modules.
Support store hot reloading. Handle state preservation. Implement HMR handlers. Support development workflow. Handle module updates.
Test store components separately. Handle action testing. Support mutation testing. Implement test utilities. Handle mock data.
Initialize store with default state. Handle async initialization. Support dynamic registration. Implement initialization patterns.
Create middleware for store operations. Handle action middleware. Support middleware chain. Implement middleware patterns.
Optimize store performance. Handle large state trees. Support selective updates. Implement optimization strategies.
Implement deployment strategies. Handle environment configuration. Support production optimization. Implement deployment patterns.
Mutations are synchronous functions that modify state. Only way to change state in Vuex. Committed using commit method. Example: commit('increment', payload).
Compose multiple stores. Handle store dependencies. Support store inheritance. Implement composition patterns. Handle state sharing.
Handle store access control. Implement state protection. Support security patterns. Handle sensitive data.
Implement state migrations. Handle version updates. Support migration strategies. Handle backwards compatibility.
Create comprehensive documentation. Generate API docs. Support example usage. Implement documentation systems.
Create plugins for additional functionality. Handle state subscriptions. Support plugin options. Implement plugin patterns. Handle plugin lifecycle.
Subscribe to state changes. Handle mutation/action subscriptions. Support watchers. Implement subscription patterns.
Manage error handling in store. Handle global errors. Support error recovery. Implement error patterns. Handle error reporting.
Create complex store architectures. Handle advanced scenarios. Support pattern composition. Implement advanced strategies.
Track store operations. Handle performance monitoring. Support debugging tools. Implement monitoring strategies.
Design scalable store systems. Handle store organization. Support architecture patterns. Implement design principles.
Create comprehensive test suites. Handle integration testing. Support unit testing. Implement test strategies.
Vuex and Pinia are state management patterns/libraries for Vue.js applications. Vuex is traditional with mutations, while Pinia is newer with simpler API. Both handle centralized state management with reactive updates.
Vuex has five core concepts: State, Getters, Mutations, Actions, and Modules. State holds data, Getters compute derived state, Mutations change state synchronously, Actions handle async operations.
Use defineStore with unique id and options or setup syntax. Contains state, getters, and actions. Example: defineStore('counter', { state: () => ({ count: 0 }) }).
Actions handle asynchronous operations. Can commit mutations (Vuex) or directly modify state (Pinia). Support business logic and API calls. Can return promises.