Static GitHub Issues

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

prev: Custom Server error page
next: 'from' route object in context undefined in ssr but not in spa mode.

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.

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1879">#c1879</a>)</em></sub></div>