import Cache from '@/utils/cache' import Constant from '@/utils/constant' const val = Cache.get(Constant.CACHE_TAB_SELECTED) const getDefaultState = () => { return { index: val === undefined ? 1 : val } } const state = getDefaultState() const mutations = { SET_INDEX: (state, index) => { Cache.set(Constant.CACHE_TAB_SELECTED, index) state.index = index } } const actions = { index({ commit }, index) { commit('SET_INDEX', index) } } export default { namespaced: true, state, mutations, actions }