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 }
原文:https://www.cnblogs.com/shoestrong/p/10826952.html