Use Keep-alive to optimize web page performance
Every time we enter the city page, our json will be reloaded.
then what should we do?
What does it mean to use keep-alive? That is, after I load it once, we will put the loaded into the memory, and use it directly when we execute this function next time.
But using keep-alive, when we need to refresh, there is another way to re-request.
We add a calculated attribute and add the city to the end of the request.
When we use keep-alive, it will bring a function activated(). Even if our data enters the cache, it will re-request when we refresh. We can do this.
- Add data from the previous city
- When the first request is made, the city is assigned to lastCity. When it is refreshed again, it is judged whether it is the previous city or not, and then the getHomeInfo request is called again.