【发布时间】:2021-12-14 16:50:23
【问题描述】:
我正在创建一个 React Native,在其中我使用 Fetch 将表单的数据发送到后端 Node.js,一切正常,但在 fetch api 后我无法执行任何操作,即使 console.log 没有运行。
React-Native 代码:
const PostData = () =>{
console.log("Posting");
//Sending Request to Node.js using Fetch API
fetch("http://192.168.0.107:3000/Adminsignup", {
//Setting Method
method:"POST",
//Setting Headers
headers:{
//Setting Content-Type
"Content-Type" : "application/json"
},
//Stringifying the email and password and storing it into body
body:JSON.stringify({
name,
gmail,
password,
retype
})
}).then(res=>{
console.log(res);
}).catch(err=>{
console.log(err);
})
}
.then 和 .catch 的 fetch api 不起作用。
【问题讨论】:
-
为什么要混合 async-await 和 promise? .使用异步等待或承诺
-
好的,我现在正在使用异步,但我仍然没有得到回复
-
如果您真的完全切换到异步样式,并且不再使用
then()anymore,那么请编辑您的帖子以显示新代码。 -
我尝试过承诺,现在我的代码已更新
-
在您分享的代码中,您定义了一个函数,但您没有调用它。你真的在任何地方打电话给
PostData()吗?
标签: react-native