W
W
wlms2019-03-13 18:13:14
Vue.js
wlms, 2019-03-13 18:13:14

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

1 answer(s)
D
Dima Pautov, 2019-03-13
@bootd

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()
}

Then, when initializing the application, the necessary data will first be requested

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question