pinia is a Vue-specific state management library that allows state sharing across components or pages
The difference between pinia and vuex :
- More friendly TypeScript support, Vuex's previous support for TS was very unfriendly
- Compared to Vuex, Pinia provides a simpler API with less ceremony, providing a Composition-API style API
- No more nested structures of modules
- There is also no concept of namespaces anymore, no need to remember their complex relationships
Know the Store
A Store (such as Pinia) is an entity that can save the global state, so that you can define any number of Stores to manage your state, such as: state, getters, actions
define a store
Store is defined using defineStore(), which also requires a name, passed as the first parameter
State is the core of store, similar to data, which can be used to store global state
Getters are similar to computed components used to encapsulate computed properties and use caching
Actions can modify the state