A
A
Alexander Sharomet2018-10-15 14:45:42
Vue.js
Alexander Sharomet, 2018-10-15 14:45:42

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

index.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
})

store connection:
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
});

action.js:
export default {
    SET_USER({commit}, user) { //При вызове этого экшена я получаю ошибку
        commit('SET_USER', user) // Передаю данные в mutation
    }
}

Action call:
signIn() {
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'));
}

What is it connected with? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-10-15
@sharomet

Maybe, after all, there should be actions instead of action? Likewise with mutations.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question