Answer the question
In order to leave comments, you need to log in
How to wait for vuejs login data to load?
I have the beforeEnter method configured on the routes. It looks to see if there is a user in the vuex state. If not, it redirects to auth. When the application is loaded, the state is empty and it immediately switches to auth, and the user is loaded in a second. In other words, the user does not have time to unload into the state and therefore a redirect occurs. Question: how to wait for the data, and then transfer to auth?
Answer the question
In order to leave comments, you need to log in
You need not beforeEnter , but beforeEach , in which to check user
A before starting the application in the root vue instance in the created hook to query the user
//App.vue
async created () {
await this.getUser()
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question