Browse Source

修改app.vue,刷新页面时保存store中的数据

unknown 4 years ago
parent
commit
5b0e05560c
1 changed files with 23 additions and 1 deletions
  1. 23 1
      src/App.vue

+ 23 - 1
src/App.vue

@@ -3,7 +3,29 @@
         <router-view />
     </div>
 </template>
-
+<script>
+export default {
+    data() {
+        return {}
+    },
+    mounted() {
+        // 监听页面刷新事件
+        window.addEventListener('unload', this.unload)
+        // 页面加载完成后,移除session里的存储的信息
+        window.addEventListener('load', this.load)
+    },
+    methods: {
+        unload() {
+            // const { userInfo, projectId, menuStatus,manualAutoMode } = this.$store.state;
+            const state = this.$store.state
+            sessionStorage.setItem('state', JSON.stringify(state))
+        },
+        load() {
+            sessionStorage.clear()
+        }
+    }
+}
+</script>
 <style lang="less">
 body,
 h1,