美文网首页
Vuex刷新丢失问题

Vuex刷新丢失问题

作者: FAKEEER | 来源:发表于2020-10-13 15:30 被阅读0次
 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));
    });
  }

相关文章

网友评论

      本文标题:Vuex刷新丢失问题

      本文链接:https://www.haomeiwen.com/subject/ypmvpktx.html