使用map的简洁写法好像没试出来怎么用,但是常规写法如下:
vuex:
import Vue from "vue"; import Vuex from "vuex"; import userStore from "./modules/userStore"; Vue.use(Vuex); export default new Vuex.Store({ modules: { userStore } });
我这里写个获取后台接口的token在vuex
然后JS获取TOKEN:
import store from '@/store'
request.headers.Authorization = store.getters['userStore/getToken'];