当前位置:网站首页>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
边栏推荐
- Plastic floating dock Industry Research Report - market status analysis and development prospect forecast
- ~90z axis translation
- Go web programming practice (1) -- basic syntax of go language
- [shutter] statefulwidget component (bottom navigation bar component | bottomnavigationbar component | bottomnavigationbaritem component | tab switching)
- Construction and maintenance of business websites [9]
- 关于测试用例
- Get weekday / day of week for datetime column of dataframe - get weekday / day of week for datetime column of dataframe
- Physical layer cables and equipment
- tinymce可视化编辑器增加百度地图插件
- [C language] [sword finger offer article] - replace spaces
猜你喜欢

GEE:(二)对影像进行重采样

tinymce可视化编辑器增加百度地图插件

如何访问kubernetes API?

Gbase8s database type

System (hierarchical) clustering method and SPSS implementation

It is said that this year gold three silver four has become gold one silver two..

Unexpectedly, there are such sand sculpture code comments! I laughed

*C language final course design * -- address book management system (complete project + source code + detailed notes)

treevalue——Master Nested Data Like Tensor

pip安装whl文件报错:ERROR: ... is not a supported wheel on this platform
随机推荐
Basic IO interface technology - microcomputer Chapter 7 Notes
Jar package startup failed -mysql modify the default port number / set password free enter
【剑指 Offer】56 - I. 数组中数字出现的次数
TinyMCE visual editor adds Baidu map plug-in
Baidu sued a company called "Ciba screen"
Introduction to the principle of geographical detector
[zero foundation I] Navicat download link
Construction and maintenance of business websites [9]
Cloud computing technology [2]
Image segmentation using pixellib
CVPR论文解读 | 弱监督的高保真服饰模特生成
Construction and maintenance of business website [5]
[sword finger offer] 56 - I. the number of numbers in the array
~91 rotation
[shutter] statefulwidget component (bottom navigation bar component | bottomnavigationbar component | bottomnavigationbaritem component | tab switching)
Physical layer cables and equipment
Introduction to victoriametrics
【剑指 Offer】57. 和为s的两个数字
beginning
Analysis of enterprise financial statements [4]