H
H
hckn2019-01-01 15:10:37
Vue.js
hckn, 2019-01-01 15:10:37

How to wait for the initial filling of the store before loading the page?

I need to authenticate the initial page load (that is, once, and not for each transition already inside the application) by requesting /api/init, receiving a response, filling the store, and only then let the user in or not. I can not understand the earliest place in the View application where this can be done?
If I do this in main.js, then the application does not wait for the result of the request.
Doing this in everyone beforeEnteris not suitable, although it works, because. I only need it once when loading the page.
It doesn’t look very appropriate in a hook App.vue, I want to move this logic to another place.
UPD: In a hook App.vue, this is not suitable, because. The page is loaded without waiting for the end of the request.
But where?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
0
0xD34F, 2019-01-01
@hckn

In the App.vue hook, it doesn’t look very appropriate, I want to move this logic to another place.

What kind of logic is this? You will have a simple action call in created, this is one line. Alright, do it.

V
Vladimir, 2019-01-03
@99percent

There is an option to use SSR, where you can just implement a request to the api with filling the store, and only after that the application will start loading.

A
Andrey, 2019-01-05
@Andrew-Bogdanov

Maybe it makes sense to use Nuxt? There is already the nuxtServerInit hook you need, you can also make serverMiddleware, there are many ready-made examples

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question