A few days ago, I encountered a bug and searched for a long time to find that it was vUE’s problem: there was a requirement to poll a background interface every two seconds on the page, no matter whether you leave the page or not, as long as you trigger this timer, it can not be turned off, can only wait for it to finish its execution.
Problem a
Since the timer cannot be emptied, when you run the timer on this page, go to another page, and then return to this page, a new timer will be triggered
Question 2
I started by putting a flag in localStroage to see if the timer was running or not. If it was running, no new timer would be generated, and if it wasn’t, a new timer would be generated. So the problem is that when you refresh the page, the browser will clear the timer that you just had. They don’t erase localStroage
premium
I think, it is can be done with vueX, give the flag set an initial value, when he was a page refresh, will get back to the initial value, you can perform this timer, alacrity, the results showed that the timer is really good, but not the data on the page rendering, timer interface returned to the new data, but still the old data on a page.
In about an hour and a half
I suddenly remembered, because the page to initialize every time they come in over the data, data in a timer is not you now the data on the page, the timer in this point to you on this, a page timer interface of the data returned is also a page on your data, you are on this page is not, of course, So the data on the page is not refreshed.
Finally got to the crux of the matter
If you don’t need caching for other pages, you can use dynamic caching with include
The last
This article is really well written, juejin.cn/post/684490… This will help you understand