Skip to content

Commit 4eed17c

Browse files
committed
feat: add plugin
1 parent ff97ac4 commit 4eed17c

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// from https://forum.vuejs.org/t/best-way-to-clear-localstorage/63125/4
2+
3+
let version = process.env.APP_VERSION;
4+
5+
// Store intial version in localStorage
6+
if (!localStorage.getItem('app_version')) {
7+
localStorage.setItem('app_version', version);
8+
}
9+
10+
console.log('Initial app version', localStorage.getItem('app_version'))
11+
12+
// Now lets imagine the user comes back to your app after a period of time...
13+
// The version in package.json has changed and therefore you need to update your localStorage version
14+
15+
console.log('New app version', version)
16+
17+
// This timeout is just for this example
18+
if (localStorage.getItem('app_version') !== version) {
19+
if (confirm(`New app version ${version} available, please refresh`)) {
20+
// Refresh the page and clear the app_version, so it can be set again with the latest version
21+
localStorage.removeItem('app_version');
22+
localStorage.clear();
23+
24+
// Fire a refresh
25+
window.location.reload();
26+
}
27+
}
28+

0 commit comments

Comments
 (0)