TypeError: Cannot read property 'dispatch' of undefined尝试提交 Login.vue 表单时出现错误。我将我的更改function()为只是data()等,就像建议的 SO 答案一样,但这并没有帮助......
index.js:
import Vue from 'vue';
import Vuex from 'vuex';
import auth from './store/auth.module.js';
Vue.use(Vuex);
export default new Vuex.Store({
//plugins: [createPersistedState({ storage: sessionStorage })],
state: { },
mutations: { },
actions: { },
modules: { auth }
})
主.js:
import Vue from 'vue'
import App from './App.vue'
import router from './router';
import store from './store/auth.module';
import "./assets/css/tailwind.css";
import '@/assets/css/tailwind.css';
Vue.config.productionTip = false;
new Vue({
router,
store,
render: h => h(App),
}).$mount('#app');
auth-header.js:
export default function authHeader() {
let user = JSON.parse(localStorage.getItem('user'));
if (user && user.accessToken) {
return { Authorization: 'Bearer ' + user.accessToken };
} else {
return {};
}
}
user.service.js:
import axios from 'axios';
import authHeader from './auth-header';
const API_URL = 'localhost:8088/testproject/api/users';
class UserService {
getPublicContent() {
return axios.get(API_URL + '/all');
}
getUserBoard() {
return axios.get(API_URL + '?role=user', { headers: authHeader() });
}
getModeratorBoard() {
return axios.get(API_URL + '?role=mod', { headers: authHeader() });
}
getAdminBoard() {
return axios.get(API_URL + '?role=admin', { headers: authHeader() });
}
}
export default new UserService();
元芳怎么了
繁花如伊
慕容708150
MYYA
相关分类