← Vue.js learning pathVue.js · Module 8 of 10
State management with Pinia
Share state across components with Pinia stores.
📖 Key ideas
- Pinia is the official Vue store library.
- defineStore("cart", { state, getters, actions }).
- Use it: const cart = useCartStore().
- Getters are computed values; actions change state.
- Pinia works with Vue DevTools.
💡 Real-life example: A Pinia store is a shared notice board: any component can read it and authorised actions update it.
PiniaOfficial Vue state library
defineStoreCreates a store
GetterComputed value from store state
ActionMethod that changes store state