N
N
nastya_zholudeva2017-11-14 18:00:31
OpenCV
nastya_zholudeva, 2017-11-14 18:00:31

How to make it so that the data that has just been loaded into LocalStorage can be immediately used in the code?

I have requests to the API on my site, one of the parameters for the request 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 necessary request to the API. As a result, we get such an object
{
                        "id": 2379,
                        "name": "г. Москва",
                        "region": "Московская обл.",
                        "lat": "55.755814",
                        "long": "37.617635",
                        "update_at": 1489006800
                    };

which we put in LocalStorage.
However, if you clear LocalStorage and reload the page, then
console.log((JSON.parse(localStorage.getItem('town'))));
returns null. And therefore there is nothing to put in town_id.
More details on the video. https://www.dropbox.com/s/mzek869z13kbrea/ice_vid...
Working with vue.js

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Toxic-cloud, 2019-08-23
@Toxic-cloud

You don’t have to set the average difficulty, just there is no permission for the command
Run with sudo, by the way, you also installed opencv yesterday
And you may encounter another problem
In the OPENCV_EXTRA_PATH= parameter, the path to the modules, that is, the library that you downloaded along with the main one

T
tema_sun, 2017-11-14
@tema_sun

And what is the difficulty in checking the localstoraldzh and if it is empty, then send a request to the api?
ps put

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question