我正在尝试在 react-native 中本地获取 laravel API。当我尝试使用远程 url 时,它可以工作,但不能与本地服务器一起使用。我正在使用 android studio 模拟器和
react-native => 0.59.8,
laravel => 5.7
我的代码
async submit() {
//https://facebook.github.io/react-native/movies.json => this works
try {
let response = await fetch('localhost:8000/api/coins');
let responseJsonData = await response.json();
console.log(responseJsonData, 'data');
} catch (e) {
console.log(e, 'error')
}
};
错误
05-20 14:46:08.167 4749 8885 I ReactNativeJS: { [TypeError: Network request failed]
05-20 14:46:08.167 4749 8885 I ReactNativeJS: line: 24115,
05-20 14:46:08.167 4749 8885 I ReactNativeJS: column: 31,
05-20 14:46:08.167 4749 8885 I ReactNativeJS: sourceURL: 'http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false' }, 'error'
PIPIONE
相关分类