当前位置:网站首页>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
边栏推荐
- Chargement de l'image pyqt après décodage et codage de l'image
- 记录一下微信、QQ、微博分享web网页功能
- China's Micro SD market trend report, technology dynamic innovation and market forecast
- 暑期第一周总结
- beginning
- Oriental Aesthetics and software design
- [zero foundation I] Navicat download link
- 2019 Nanchang (relive the classic)
- Physical layer cables and equipment
- How do I access the kubernetes API?
猜你喜欢
tinymce可视化编辑器增加百度地图插件
Five message formats of OSPF
[shutter] shutter layout component (physicalmodel component)
treevalue——Master Nested Data Like Tensor
Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
MySQL learning record (8)
D4:非成对图像去雾,基于密度与深度分解的自增强方法(CVPR 2022)
Gee: (II) resampling the image
Oriental Aesthetics and software design
How to test the process of restoring backup files?
随机推荐
PIP version update timeout - download using domestic image
[zero foundation I] Navicat download link
Off chip ADC commissioning record
System (hierarchical) clustering method and SPSS implementation
Unexpectedly, there are such sand sculpture code comments! I laughed
Huawei Hongmeng watch achieves fireworks display effect on New Year's Eve
Plastic granule Industry Research Report - market status analysis and development prospect forecast
Market trend report, technical innovation and market forecast of China's Micro pliers
一周生活
Jar package startup failed -mysql modify the default port number / set password free enter
Analysis of enterprise financial statements [4]
Research Report on minimally invasive medical robot industry - market status analysis and development prospect prediction
Research Report on market supply and demand and strategy of China's Plastic Geogrid industry
MySQL learning record (5)
A specially designed loss is used to deal with data sets with unbalanced categories
Research Report on market supply and demand and strategy of microplate instrument industry in China
China's log saw blade market trend report, technological innovation and market forecast
China's crude oil heater market trend report, technological innovation and market forecast
AES encryption CBC mode pkcs7padding filling Base64 encoding key 32byte iv16byte
How to prevent your jar from being decompiled?