vue 使用vuex 刷新时保存数据

created () {
      this.$store.replaceState(Object.assign(this.$store.state,JSON.parse(localStorage.getItem("beforeunload"))));
      window.addEventListener('beforeunload', ()=>{
        let state = JSON.stringify(this.$store.state)
          localStorage.setItem("beforeunload",state);
      });
    },

在created 生命周期中 保存数据 和同步数据

原文地址:https://www.cnblogs.com/buxiugangzi/p/11379178.html