vuex存数据,防止刷新数据丢失

 

 

 1 created() { 
 2   if (sessionStorage.getItem('store')) {
 3     this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem('store'))))
 4   }
 5   let isOnIOS = navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i);
 6   let eventName = isOnIOS ? 'pagehide' : 'beforeunload';
 7 
 8   window.addEventListener(eventName, () => {
 9     sessionStorage.setItem('store', JSON.stringify(this.$store.state));
10   })
11 }

 

posted @ 2019-05-07 17:41  Shoestrong  阅读(311)  评论(0编辑  收藏  举报
更多精彩请访问个人主页http://shoestrong.cc