Browse Source

App.vue 文件合并问题修改,恢复vuex数据处理

yx 4 years ago
parent
commit
78f8eaeab5
1 changed files with 11 additions and 17 deletions
  1. 11 17
      src/App.vue

+ 11 - 17
src/App.vue

@@ -20,11 +20,18 @@ export default {
             mapServerURL: `http://map.wanda.cn/editor`
         }
     },
+    /**
+     * 刷新保存vuex信息
+     */
+    created() {
+        this.$store.replaceState(Object.assign(this.$store.state, JSON.parse(localStorage.getItem('beforeunload'))))
+        localStorage.removeItem('beforeunload')
+        window.addEventListener('beforeunload', () => {
+            let state = JSON.stringify(this.$store.state)
+            localStorage.setItem('beforeunload', state)
+        })
+    },
     mounted() {
-        // 监听页面刷新事件
-        window.addEventListener('unload', this.unload)
-        // 页面加载完成后,移除session里的存储的信息
-        window.addEventListener('load', this.load)
         // 请求该项目下的楼层数据
         this.getFengMap()
     },
@@ -34,19 +41,6 @@ export default {
     methods: {
         ...mapActions(['getfmapID']),
         ...mapMutations(['SETHAVEFENGMAP']),
-        unload() {
-            // const { userInfo, projectId, menuStatus,manualAutoMode } = this.$store.state;
-            const state = this.$store.state
-            sessionStorage.setItem('state', JSON.stringify(state))
-        },
-        mounted() {
-            // 监听页面刷新事件
-            window.addEventListener('unload', this.unload)
-            // 页面加载完成后,移除session里的存储的信息
-            window.addEventListener('load', this.load)
-            // 请求该项目下的楼层数据
-            this.getFengMap()
-        },
         getFengMap() {
             if (!this.fmapID) {
                 this.getfmapID().then(() => {