vue 防止页面刷新vuex数据丢失
app.vue
created() {
if(localStorage.getItem("store")){
this.$store.replaceState(
Object.assign({},this.$store.state,JSON.parse(window.localStorage.getItem("store")))
);
}
//在页面刷新时将vuex里的信息保存到localStorage里
window.addEventListener("beforeunload",()=>{
window.localStorage.setItem("store",JSON.stringify(this.$store.state));
});
},

浙公网安备 33010602011771号