robinvdvleuten / vuex-persistedstate

💾 Persist and rehydrate your Vuex state between page reloads.
https://npm.im/vuex-persistedstate
MIT License
5.77k stars 378 forks source link

The fetchBeforeUse fearture does not work for me. #394

Closed Chu-Te-Ethan-Chen closed 3 years ago

Chu-Te-Ethan-Chen commented 3 years ago

Relevant code or config

import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/user'
import createPersistedState from 'vuex-persistedstate'
import SecureLS from 'secure-ls'
var ls = new SecureLS({ isCompression: false })
Vue.use(Vuex)

export default new Vuex.Store({
  plugins: [createPersistedState({
    storage: {
      getItem: (key) => ls.get(key),
      setItem: (key, value) => ls.set(key, value),
      removeItem: (key) => ls.remove(key),
    },
    fetchBeforeUse: true,
  })],
  state: {
  },
  mutations: {
  },
  actions: {
  },
  getters: {
  },
  modules: {
    user,
  }
})

What you did: I set fetchBeforeUse: true in option. And I wish the new tab can getState from localstorage.

What happened: The new tab does not getState from localstorage.

Problem description: Is there an example to demonstrate the fetchBeforeUse feature ? Thanks!

Chu-Te-Ethan-Chen commented 3 years ago

I find out that window.addEventListener('storage', (e) => { }) can meet my need. ref: #234