1.在App.vue下加入
mounted() {window.addEventListener("unload", this.saveState);},methods: {saveState() {sessionStorage.setItem("state", JSON.stringify(this.$store.state));}}
2.在store下的index.js文件下修改
state:sessionStorage.getItem('state') ? JSON.parse(sessionStorage.getItem('state')): {},