← Vue.js learning path
Vue.js · Module 8 of 10

State management with Pinia

Share state across components with Pinia stores.

📖 Key ideas

  1. Pinia is the official Vue store library.
  2. defineStore("cart", { state, getters, actions }).
  3. Use it: const cart = useCartStore().
  4. Getters are computed values; actions change state.
  5. 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