Vuex刷新丢失问题

2020-10-13  本文已影响0人  FAKEEER
 created () {
    // 阻止刷新vuex丢失
    if (localStorage.getItem('store')) {
      this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(localStorage.getItem('store') || '{}')));
      localStorage.removeItem('store');
    }
    window.addEventListener('beforeunload', () => {
      localStorage.setItem('store', JSON.stringify(this.$store.state));
    });
  }
上一篇 下一篇

猜你喜欢

热点阅读