defineStore: State, Getters, Actions
Options store vs Setup store, state as function, computed getters, async actions.
The Three Pillars of a Store
An option store has three parts: state (the data), getters (derived values), and actions (methods that change state). You define all three inside defineStore.
Defining a Store
defineStore takes a unique id string and an options object. It returns a composable — by convention named useXxxStore.
import { defineStore } from 'pinia'
export const useCounterStore = defineStore('counter', {
// state, getters, actions go here
})All lessons in this course
- Pinia vs Vuex: Why the Switch
- defineStore: State, Getters, Actions
- Composing Stores and Cross-Store Access
- Pinia Persistence and Devtools