Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To provide an argument to a Pinia store, you can use the createPinia function and pass the argument as a parameter:

import { createPinia } from 'pinia'

const pinia = createPinia()

const myStore = pinia.defineStore('myStore', {
  state: () => ({
    myArgument: null
  }),
  actions: {
    setMyArgument (value) {
      this.myArgument = value
    }
  }
})

// Provide the argument when creating a new store instance
const storeWithArgument = myStore({ myArgument: 'my value' })

console.log(storeWithArgument.myArgument) // 'my value'

In the example above, the myStore store has a myArgument property in its state, and a setMyArgument action to update its value. To provide an argument to the store instance, call the store function with the argument as the parameter, and access it in the store instance using this.myArgument.