tab.js 538 B

12345678910111213141516171819202122232425262728293031
  1. import Cache from '@/utils/cache'
  2. import Constant from '@/utils/constant'
  3. const val = Cache.get(Constant.CACHE_TAB_SELECTED)
  4. const getDefaultState = () => {
  5. return {
  6. index: val === undefined ? 1 : val
  7. }
  8. }
  9. const state = getDefaultState()
  10. const mutations = {
  11. SET_INDEX: (state, index) => {
  12. Cache.set(Constant.CACHE_TAB_SELECTED, index)
  13. state.index = index
  14. }
  15. }
  16. const actions = {
  17. index({ commit }, index) {
  18. commit('SET_INDEX', index)
  19. }
  20. }
  21. export default {
  22. namespaced: true,
  23. state,
  24. mutations,
  25. actions
  26. }