0Pricing
Vue Academy · Lesson

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

  1. Pinia vs Vuex: Why the Switch
  2. defineStore: State, Getters, Actions
  3. Composing Stores and Cross-Store Access
  4. Pinia Persistence and Devtools
← Back to Vue Academy