diff --git a/src/App.vue b/src/App.vue index def7824fc..e10d0881c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -28,13 +28,30 @@ export default { }, created () { // 在页面加载时读取sessionStorage - if (sessionStorage.getItem('store')) { - this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem('store')))) + // if (sessionStorage.getItem('store')) { + // this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem('store')))) + // } + // // 在页面刷新时将store保存到sessionStorage里 + // window.addEventListener('beforeunload', () => { + // sessionStorage.setItem('store', JSON.stringify(this.$store.state)) + // }) + //ios刷新时vuex信息保留 + let isiOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端 + if (isiOS) { + //在页面刷新时将vuex里的信息保存到缓存里 + window.addEventListener("pagehide", () => { + localStorage.setItem("store", JSON.stringify(this.$store.state)) + }) + //在页面加载时读取localStorage里的状态信息 + localStorage.getItem("store") && this.$store.replaceState(Object.assign(this.$store.state,JSON.parse(localStorage.getItem("store")))); + } else { + //在页面刷新时将vuex里的信息保存到缓存里 + window.addEventListener("beforeunload", () => { + localStorage.setItem("store", JSON.stringify(this.$store.state)) + }) + //在页面加载时读取localStorage里的状态信息 + localStorage.getItem("store") && this.$store.replaceState(Object.assign(this.$store.state,JSON.parse(localStorage.getItem("store")))); } - // 在页面刷新时将store保存到sessionStorage里 - window.addEventListener('beforeunload', () => { - sessionStorage.setItem('store', JSON.stringify(this.$store.state)) - }) }, mounted(){ },