App.vue文件夾加入以下代碼
created() { //在頁面加載時讀取sessionStorage裏的狀態信息 if (localStorage.getItem("store") ) { this.$store.replaceState(Object.assign({}, this.$store.state,JSON.parse(localStorage.getItem("store")))) } //在頁面刷新時將vuex裏的信息保存到sessionStorage裏 window.addEventListener("beforeunload",()=>{ localStorage.setItem("store",JSON.stringify(this.$store.state)) }) }