axios.post 的 .then() 无法运行
.then() of axios.post is not functioning
我是 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);
});
}
};
dispatch 用于 redux 功能。
我尝试删除函数的 return 语句并使用 async,await 。
console.log 不打印。如果您能提供帮助,请提前致谢。
只是菜鸟问题。后端端响应没来。始终使用邮递员或任何其他工具检查您的后端。 @user3791775
谢谢大家的宝贵时间。
我是 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);
});
}
};
dispatch 用于 redux 功能。 我尝试删除函数的 return 语句并使用 async,await 。 console.log 不打印。如果您能提供帮助,请提前致谢。
只是菜鸟问题。后端端响应没来。始终使用邮递员或任何其他工具检查您的后端。 @user3791775 谢谢大家的宝贵时间。