Advertisement
machtl

Untitled

Sep 7th, 2019
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import VuexPersistence from 'vuex-persist'
  2. import localforage from 'localforage'
  3. const vuexLocal = new VuexPersistence({
  4.   storage: localforage,
  5.   strictMode: false,
  6.   asyncStorage: true,
  7.   restoreState: (key, storage) => {
  8.     return new Promise(resolve => {
  9.       storage.getItem(key).then(data => {
  10.         resolve(data)
  11.         store._vm.$root.$emit('storageReady')
  12.         store._vm.$root.storageReady = true
  13.         if (data && data.auth && data.auth.token) {
  14.           pAxios.defaults.headers.common['Authorization'] = data.auth.token
  15.         }
  16.         store.state.loading = false
  17.       })
  18.     })
  19.   }
  20. })
  21. const store = new Vuex.Store({
  22.   modules: {
  23.     modules,
  24.   },
  25.   getters: {
  26.     getBla: state => param => getBla(state, param),
  27.   },
  28.   state: {
  29.     loading: true
  30.   },
  31.   plugins: [vuexLocal.plugin]
  32. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement