vue.js - 仅当出现错误时,我如何才能捕获错误?
问题描述
即使响应是 .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')
解决方案
推荐阅读
- html - 跟踪是否在 MongoDB 中单击了复选框/按钮的最佳方法是什么?
- sql - 如何获取 Azure 数据库的上次访问日期时间
- android - 更新 Firebase 实时数据库中的现有数据
- python - Apache Beam Python:条件和中断
- c# - 代码中的集成安全与密码 - 带有一些 SQL 编写的小型 .net 应用程序
- javascript - 如何使用 dropzone 5.7 在 php 中上传表单元素以及数量有限的文件
- laravel-5 - Laravel 5.8 如何包含 node_modules
- php - 编辑时如何处理双图像文件
- excel - 插入图片宏在 64 位 Excel 上不起作用
- python - Pandas(DataFrame):如何在新行中写入新数据