Skip to content

Initialization ordering: can I manually initialize Pinia instance **before** Vue app instance is created? #2894

Closed Answered by posva
IS-Kuan asked this question in Help and Questions
Discussion options

You must be logged in to vote

See https://pinia.vuejs.org/core-concepts/outside-component-usage.html#Using-a-store-outside-of-a-component. In short, put your pinia in a different file and import it in those singletons and pass it explicitly to the useStore() functions.

// src/pinia.ts
export const pinia = createPinia()
// src/singleton.ts
import { useStore } from './stores/store.ts
import { pinia } from './pinia.ts

useStore(pinia)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by posva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants