vuex版本不对,获取不到store,vue默认vue3版本,vuex默认vuex4版本,vuex4只能在vue3中使用,在vue2中能使用vuex3,那么不能默认下载最新的版本
npm install vuex@3 --save
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
let defaultToken = ''
try {
if (JSON.parse(localStorage.getItem('token'))) {
defaultToken = localStorage.token
}
// eslint-disable-next-line no-empty
} catch (e) {}
const store = new Vuex.Store({
state: {
token: defaultToken,
a: 'aaaaaaaaaaaa',
},
getters: {},
mutations: {
SET_TOKEN(state, data) {
state.token = data
localStorage.setItem('token', JSON.stringify(data))
},
},
actions: {},
})
export default store
链接: https://blog.csdn.net/Kylincsg/article/details/125774243