Skip to content

@pinia/root / pinia / mapStores

mapStores()

ts
function mapStores<Stores>(...stores): _Spread<Stores>

Allows using stores without the composition API (setup()) by generating an object to be spread in the computed field of a component. It accepts a list of store definitions.

Type Parameters

Stores extends any[]

Parameters

• ...stores: [...Stores[]]

list of stores to map to an object

Returns

_Spread<Stores>

Example

js
export default {
  computed: {
    // other computed properties
    ...mapStores(useUserStore, useCartStore)
  },

  created() {
    this.userStore // store with id "user"
    this.cartStore // store with id "cart"
  }
}

Released under the MIT License.