1234567891011121314151617181920212223242526272829303132333435363738 |
- import { getToken, setToken } from '@/utils/auth'
- import Cache from '@/utils/cache'
- const getDefaultState = () => {
- return {
- token: getToken(),
- info: Cache.get('userInfo')
- }
- }
- const state = getDefaultState()
- const mutations = {
- SET_TOKEN: (state, token) => {
- setToken(token)
- state.token = token
- },
- SET_INFO: (state, info) => {
- Cache.set('userInfo', info)
- state.info = info
- }
- }
- const actions = {
- token({ commit }, token) {
- commit('SET_TOKEN', token)
- },
- info({ commit }, info) {
- commit('SET_INFO', info)
- }
- }
- export default {
- namespaced: true,
- state,
- mutations,
- actions
- }
|