F
F
flafy42018-08-31 00:46:22
Vue.js
flafy4, 2018-08-31 00:46:22

How to implement page preload before navigating to it in Vue JS?

How to make the page load before going to it? A simple example. There is a component that fires at a certain route, the component describes the logic in which, in turn, there are requests to the API. Therefore, when there is a transition to a page, for example, a user profile, its data is empty for literally a second, only after the infa from the database appears, the data appears.
It is necessary to achieve that the user, when clicking, for example, on the same profile, sees some kind of download (it doesn’t matter, I’ll have enough output to the console for now), and only after the logic has worked out and all requests to the API stop, there will be a transition to this page.
I hope you got what I meant. Thank you in advance for your reply, dear friend ;)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-08-31
@flafy4

In the component you are interested in, define the beforeRouteEnter hook - in it, you initiate the receipt of data. How it specifically looks like - directly executing a request, or calling an action - you know better here. After receiving the data, pull next. Everything.
UPD. No, not everything. If you don’t really understand what I mean, I made a small example . Three routes, the first two mean nothing, the last one shows the data from the storage. And with each transition, it initiates their update.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question