V
V
Vitalionus2019-11-10 17:39:50
Vue.js
Vitalionus, 2019-11-10 17:39:50

How to write to localStorage via axios before app loads?

My application must receive data from another server in order to work, if this data is not received, all pages in the router must be disabled until the data is received except the main one.
The data I receive in beforeEach
But the matter is that for the very first time they come later than the component is created. Therefore, in the component
mydata = null

data() {
    return {
      mydata: JSON.parse(localStorage.getItem('mydata')),
    };

What logic should be in general if you need to first get the data before loading the component. For example, the server might take 2 seconds to respond.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question