mirror of
http://112.124.100.131/GFRS/ebiz-h5.git
synced 2025-12-09 02:56:43 +08:00
vuex 中store存储数据 页面刷新 ios手机导致数据丢失问题兼容处理
This commit is contained in:
29
src/App.vue
29
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(){
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user