环境
我正在使用React Native和Expo开发移动应用。
同时,在我的本地环境中使用Laravel开发api(http://localhost:8000/)。
该应用程序在Expo客户端应用程序上运行。
我的目标
我想从api获取数据。
代码
App.js
componentDidMount() {
return fetch('http://localhost:8000/api/test')
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
})
.catch((error) => {
console.error(error);
});
}
错误
类型错误: 网络请求失败
Expo 版本
3.22.3
如果您能给我任何建议,我将不胜感激。
https
更好? - 高鵬翔