[英]React native fetch data
我在获取数据时遇到问题。 我的朋友创建了 Rest Api。 有我的乐趣:
const AnyCors = `https://cors-anywhere.herokuapp.com/`;
const urlAllBus = `http://207.185.72.111:15430/stops?size=15`;
fetchBusStop = () => {
return new Promise((resolve, rejects) => {
fetch(AnyCors+urlAllBus)
.then((result) => {
if (!result.ok) throw result.json();
return result.json();
})
.then((result) => {
console.log(result);
resolve(result);
})
.catch((error) =>
error.then((body) => {
console.log('Bad', body);
rejects(body);
}),
);
});
};
我用 react-native 创建了一个应用程序。 当我只使用 urlAllBus 时,我的虚拟机工作正常。 问题出在物理机上。 当我尝试在 chrome 中使用 urlAllbus 时,我遇到了 CORS 问题,所以我使用了 AnyCors+urlAllBus,一切正常。 但是在虚拟机和物理机中,解决方案不起作用。 我不知道我应该做什么
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.