Home

Issue: 2119

How can I make sure that the data that has just loaded into LocalStorage can be used immediately in the code?

[issue link]

I have requests on the site for the API, one of the parameters for the query is town_id.
And the value that we substitute there is taken from LocalStorage
town_id: JSON.parse (localStorage.getItem ('town')). ​​id,
We put it there, automatically determining the user’s location and sending the required query to the API. As a result, we get such an object

                        "id": 2379,
                        "name": "Moscow",
                        "region": "Moscow region",
                        "lat": "55.755814",
                        "long": "37.617635",
                        "update_at": 1489006800
                    };};

which we place in LocalStorage.

However, if you clear the LocalStorage and reload the page, then
console.log ((JSON.parse (localStorage.getItem ('town')))));
returns null. And therefore there is nothing to lay in the town_id.
More details on the video.

This question is available on Nuxt.js community (#c1879)