[英].then() of axios.post is not functioning
我對 React 和 JS 非常陌生。 所以我正在使用 React 和 Nodejs 開發簡單的用戶管理應用程序。 我使用 axios.post 添加用戶。 因為我需要從后端獲得響應,所以我使用了 then() function 但代碼沒有到達 function。 我這樣做是正確的還是有其他方法可以接近?
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 功能。 我嘗試刪除 function 的返回語句並使用 async,await 。 console.log 不打印。 如果您能提供幫助,請提前致謝。
只是菜鳥問題。 后端響應沒有來。 始終使用 postman 或任何其他工具檢查您的后端。 @user3791775 感謝大家的寶貴時間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.