当前位置:网站首页>Destroy in beforedestroy invalid value in localstorage
Destroy in beforedestroy invalid value in localstorage
2022-07-02 21:48:00 【Bug pill】
beforeDestroy Medium destruction localStorage Invalid data in
Purpose : Delete when closing the window localStorage Data in
Method 1:beforeDestroy Delete in
beforeDestroy() {
localStorage.removeItem("info");
}
Want to delete when the component is destroyed localStorage The variables in the , It turned out to be invalid
beforeDestroy It will not be executed when the page is refreshed , But it will be executed when the page jumps (this. r o u t e r . p u s h , t h i s . router.push,this. router.push,this.router.replace), But it will not be executed when the window is closed
When it's time to force the window to close , Browsers will be in js The execution of the gap immediately aborts all subsequent js perform (vue Of beforeDestroy No exception ), And close the window .
Method 2:unload Delete
mounted() {
window.addEventListener("unload", () => {
localStorage.removeItem("hello");
});
},
It can achieve the effect of deletion , But there's a problem , Even when the page is refreshed , This is not the desired result
Finally, it was changed to put sessionStorage It's in , Or back to the original idea
onload onunload beforeunload Execution time of
When the page is loaded, only onload
Execute... Before closing the page onbeforeunload, Last onunload
Execute... Before page refresh onbeforeunload, then onunload, Last onload
边栏推荐
- Basic IO interface technology - microcomputer Chapter 7 Notes
- Capacity expansion mechanism of ArrayList
- Accounting regulations and professional ethics [16]
- MySQL installation failed -gpg verification failed
- [sword finger offer] 56 - I. the number of numbers in the array
- MySQL learning record (2)
- ~91 rotation
- Market trend report, technical innovation and market forecast of China's Micro pliers
- MySQL inserts Chinese data and reports an error. Set the default collation
- pip安装whl文件报错:ERROR: ... is not a supported wheel on this platform
猜你喜欢
[shutter] statefulwidget component (image component | textfield component)
关于测试用例
Analysis of neural network
[shutter] shutter layout component (opacity component | clipprect component | padding component)
Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
[shutter] shutter layout component (wrap component | expanded component)
[shutter] shutter page Jump (route | navigator | page close)
Interpretation of CVPR paper | generation of high fidelity fashion models with weak supervision
[shutter] shutter layout component (Introduction to layout component | row component | column component | sizedbox component | clipoval component)
[Yu Yue education] reference materials of analog electronic technology of Nanjing Institute of information technology
随机推荐
PIP version update timeout - download using domestic image
D4:非成对图像去雾,基于密度与深度分解的自增强方法(CVPR 2022)
Baidu sued a company called "Ciba screen"
Get weekday / day of week for datetime column of dataframe - get weekday / day of week for datetime column of dataframe
Redis分布式锁故障,我忍不住想爆粗...
【剑指 Offer 】56 - II. 数组中数字出现的次数 II
[C language] [sword finger offer article] - replace spaces
Golang string segmentation
[shutter] shutter layout component (fractionallysizedbox component | stack layout component | positioned component)
~90z axis translation
Read a doctor, the kind that studies cows! Dr. enrollment of livestock technology group of Leuven University, milk quality monitoring
Research Report on plastic antioxidant industry - market status analysis and development prospect forecast
如何防止你的 jar 被反编译?
About test cases
China's Micro SD market trend report, technology dynamic innovation and market forecast
Pip install whl file Error: Error: … Ce n'est pas une roue supportée sur cette plateforme
Five message formats of OSPF
Today, I met a Alipay and took out 35K. It's really sandpaper to wipe my ass. it's a show for me
[shutter] statefulwidget component (floatingactionbutton component | refreshindicator component)
MySQL learning record (4)