A
A
Aleksandr2018-06-22 12:07:03
Vue.js
Aleksandr, 2018-06-22 12:07:03

Why does the "unknown action type" error occur?

There is such a form

<form @submit.prevent="atEmailLogin" class="login-form">
    <div class="login-form__title">
        Вход в личный кабинет агента
    </div>
    <p class="main_errors">
        {{ auth_errors }}
    </p>
    <label class="login-form__label" :class="{ error: loginForm.errors.login || auth_errors }">
        <span>Логин</span>
        <input v-model="loginForm.login" type="text" />
        <p class="errors" v-if="loginForm.errors.login">
            <i class="el-icon-close"></i>
            {{ loginForm.errors.login }}
        </p>
    </label>
    <label class="login-form__label" :class="{ error: loginForm.errors.password || auth_errors}">
        <span>Пароль</span>
        <input v-model="loginForm.password" type="password" />
        <span v-if="errors.password && errors.password.length" class="error-text">Неверный пароль</span>
        <p class="errors" v-if="loginForm.errors.password">
            <i class="el-icon-close"></i>
            {{ loginForm.errors.password }}
        </p>
    </label>
    <button class="submit-btn" type="submit">Войти</button>
</form>


atEmailLogin(event) {
    if(this.loginForm.login && this.loginForm.password) {
        this.$store.dispatch('atEmailLogin', this.loginForm)
        // .then( response => )
        // .catch(error => (this.errors = error));
    }
    this.loginForm.errors.login = '',
    this.loginForm.errors.password = '';
    if(!this.loginForm.login) {
        this.loginForm.errors.login = 'Неверный логин';
    }
    if(!this.loginForm.password) {
        this.loginForm.errors.password = 'Неверный пароль';
    }
}


Gives an error messageunknown action type: atEmailLogin

atEmailLogin({ commit }, formData) {
    console.log('123')
    return API.post("/login", formData)
    .then(response => {
        if (response && response.status === 201) {
            commit(SET_AUTH_STATE, response.data);
            return response.data;
        }
        commit(CLEAR_ERROR);
        if (response.data.success) {
            console.log('success')
            router.push('/')
        } else {
            commit(SET_ERRORS, response.data.error);
        }
    })
    .catch(error => {
        return Promise.reject(error.response.data.errors);
    });
},

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-06-22
@Sashjkeee

Well, no action. What's incomprehensible? Bad with English - use a translator.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question