Skip to content

Instantly share code, notes, and snippets.

@israeleriston
Created May 17, 2017 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save israeleriston/c93284d8ed6325a8ad01861468390158 to your computer and use it in GitHub Desktop.
Save israeleriston/c93284d8ed6325a8ad01861468390158 to your computer and use it in GitHub Desktop.
auth/store/plugins.js
import localforage from 'localforage'
import { userToken } from 'src/config'
import { setToken } from 'src/plugins/http'
import * as TYPES from './mutations-types'
const subscribe = (store) => {
store.subscribe((mutation, { auth }) => {
if (TYPES.SET_TOKEN === mutation.type) {
console.log(' subscribe ' + auth.token)
setToken(auth.token)
localforage.setItem(userToken, auth.token)
}
})
}
export default (store) => {
subscribe(store)
}
/auth/store/index.js
import state from './state'
import * as getters from './getters'
import * as actions from './actions'
import mutations from './mutations'
import plugins from './plugins'
export default { state, getters, actions, mutations, plugins }
/src/store/plugins.js
import { store as app } from '../app'
export default { ...app.plugins }
/src/store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
import * as actions from './actions'
import * as getters from './getters'
import state from './state'
import modules from './modules'
import mutations from './mutations'
import plugins from './plugins'
Vue.use(Vuex)
export default new Vuex.Store({
state,
actions,
mutations,
getters,
modules,
plugins
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment