Reactjs TypeError:react native中的Android emulator中的网络请求失败
我们尝试在react本机函数组件中加载页面时获取API调用。我们使用android仿真器Reactjs TypeError:react native中的Android emulator中的网络请求失败,reactjs,react-native,get,android-emulator,fetch,Reactjs,React Native,Get,Android Emulator,Fetch,我们尝试在react本机函数组件中加载页面时获取API调用。我们使用android仿真器 useEffect(() => { //GET request fetch('https://jsonplaceholder.typicode.com/posts/1', { method: 'GET', //Request Type }) .then((response) => response.json()) //If
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);
});
}, [])
但是我们得到了[类型错误:网络请求失败]。请让我们知道我们做错了什么