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 生命周期中 保存数据 和同步数据

posted on 2019-08-19 19:36  不锈钢子  阅读(2446)  评论(0编辑  收藏  举报