当前位置:网站首页>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
边栏推荐
- MySQL learning record (1)
- ~91 rotation
- MySQL learning record (8)
- Research Report on micro vacuum pump industry - market status analysis and development prospect prediction
- #include<>和#include“”的区别
- 记录一下微信、QQ、微博分享web网页功能
- 一周生活
- Micro SD Card Industry Research Report - market status analysis and development prospect forecast
- 地理探测器原理介绍
- [shutter] shutter layout component (fractionallysizedbox component | stack layout component | positioned component)
猜你喜欢

TinyMCE visual editor adds Baidu map plug-in

读博士吧,研究奶牛的那种!鲁汶大学 Livestock Technology 组博士招生,牛奶质量监测...
![The web version of xshell supports FTP connection and SFTP connection [detailed tutorial] continued from the previous article](/img/8f/6759b4685a129f9d10d6ea1dc8e61e.jpg)
The web version of xshell supports FTP connection and SFTP connection [detailed tutorial] continued from the previous article

pip安裝whl文件報錯:ERROR: ... is not a supported wheel on this platform

PIP version update timeout - download using domestic image

Etcd Raft 协议

如何访问kubernetes API?

MySQL learning record (9)

How to test the process of restoring backup files?

Image segmentation using pixellib
随机推荐
[use of pointer and pointer and array]
Unexpectedly, there are such sand sculpture code comments! I laughed
Redis分布式锁故障,我忍不住想爆粗...
[shutter] statefulwidget component (floatingactionbutton component | refreshindicator component)
Construction and maintenance of business website [2]
How to prevent your jar from being decompiled?
Golang string segmentation
【零基础一】Navicat下载链接
技术人创业:失败不是成功,但反思是
[shutter] shutter layout component (opacity component | clipprect component | padding component)
The web version of xshell supports FTP connection and SFTP connection
Today, I met a Alipay and took out 35K. It's really sandpaper to wipe my ass. it's a show for me
pyqt圖片解碼 編碼後加載圖片
ArrayList分析2 :Itr、ListIterator以及SubList中的坑
Cardinality sorting (detailed illustration)
~91 rotation
Construction and maintenance of business website [5]
MySQL learning record (4)
D4: unpaired image defogging, self enhancement method based on density and depth decomposition (CVPR 2022)
How is LinkedList added?