.then() 的 axios.post 不起作用



我对React和JS超级陌生。所以我正在使用 React 和 Nodejs 开发简单的用户管理应用程序。我使用 axios.post 来添加用户。因为我需要从后端获得响应,所以我使用了 then(( 函数,但代码无法到达 then 函数。我的做法是否正确,还是有其他方法可以接近?

export const addUser = (data) => {
return (dispatch) => {
dispatch(AssignUser(data));
dispatch(showForm());
return axios.post('http://localhost:4000/admin/add', data)
.then((res) => {
console.log('Inside then')
})
.catch(error => {
throw(error);
});
}
};

调度用于 redux 功能。 我尝试删除函数的返回语句,并使用了异步,等待。 控制台.log不打印。如果您能提供帮助,请提前感谢您。

只是菜鸟问题。后端响应没有到来。始终使用邮递员或任何其他工具检查您的后端。@user3791775 谢谢大家抽出宝贵时间。

最新更新