Asynchronous initialization and data recovery #2917
-
What do I do to make sure that the data is properly recovered before it's served out, that is, to make sure that the init function is executed and the init function might be an asynchronous function like reading data from indexDB. export const useUserStore = defineStore('user', {
state: () => {
return {
token: null as DataWithExpires<string> | null,
}
},
actions:{
async init(){
// read from indexdb
}
}
} It would be too inelegant to check initialization every place where you read it |
Beta Was this translation helpful? Give feedback.
Answered by
posva
Mar 3, 2025
Replies: 1 comment
-
Mount the app after the init is done: const app = createApp()
app.use(pinia)
await useUserStore(pinia).init()
app.mount() This can also be done within |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
posva
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mount the app after the init is done:
This can also be done within
App.vue
or with a boolean that toggles the Root<RouterViev>