Answer the question
In order to leave comments, you need to log in
Why is Vuex throwing an unknown action type error?
Hello.
When I call the action, I get the following error [vuex] unknown action type: SET_USER
Structure:
- store
-- index.js
-- action.js
-- mutation.js
// Подключаю все файлы store
import Vue from 'vue'
import Vuex from 'vuex'
import state from './state'
import action from './action'
import mutation from './mutation'
Vue.use(Vuex)
export default new Vuex.Store({
state,
action,
mutation
})
import store from './store/index' // store
require('./bootstrap')
window.Vue = require('vue')
Vue.component('app-component', require('./components/AppComponent.vue'))
const app = new Vue({
el: '#app',
store
});
export default {
SET_USER({commit}, user) { //При вызове этого экшена я получаю ошибку
commit('SET_USER', user) // Передаю данные в mutation
}
}
axios.post(this.$store.state.serverURI + 'login', {
email: this.email,
password: this.password
}, {headers: {'Content-Type': 'application/json'}})
.then(res => {
if(res) {
this.$store.dispatch('SET_USER', res.data); // Вызываю экшн
//this.SET_USER(res.data); // этот метод выдаёт такую же ошибку
}
})
.catch(err => console.log('Error'));
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question