File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments