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
.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-04 00:47:55 +0000
Seen: 15 times
Last updated: May 04 '23
What is the process for automatically importing pinia stores in nuxt?
What is the method to store video and audio files using webrtc on Android?
How can an extension in Chrome browser access and retrieve data from a state managed by Redux?
How to utilize Electron for loading an external site and store messages in JSON format?
How can I retrieve all the records from IndexedDB that are not equal to a specific value?
How do I store the price row in an array?
How can I combine 2 arrays into 1 array in an Angular ngrx store?