首页 > 解决方案 > 仅当出现错误时,我如何才能捕获错误?

问题描述

即使响应是 .axios 也会捕获错误success

我试图检查错误,但在我看来,这没有意义。

我的 vuex acion 中的代码有问题吗:

export const store = ({ dispatch, state, commit }, { payload, context }) => {
    return axios.post('/api/projects', payload).then((response) => {
        commit('addProject', response.data)
        commit('setProjectData', response.data)
    }).catch(function (error) {
        if (error)
        context.errors = error.response.data.errors
    })
}

//Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'error.response.data')

标签: vue.jsaxiosvuex

解决方案


推荐阅读