问题描述
我们尝试在 React Native 功能组件中加载页面时调用 API。我们使用安卓模拟器
useEffect(() => {
//GET request
fetch('https://jsonplaceholder.typicode.com/posts/1',{
method: 'GET',//Request Type
})
.then((response) => response.json())
//If response is in json then in success
.then((responseJson) => {
//Success
alert(JSON.stringify(responseJson));
console.log(responseJson);
})
//If response is not in json then in error
.catch((error) => {
//Error
alert(JSON.stringify(error));
console.error(error);
});
},[])
但我们收到[TypeError:网络请求失败]。请告诉我们我们做错了什么
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)