Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 在新项目中处理本机获取问题_React Native - Fatal编程技术网

React native 在新项目中处理本机获取问题

React native 在新项目中处理本机获取问题,react-native,React Native,接下来,我遇到了fetch()的问题,我不理解。我还没有找到一篇文章来阐明这一点 fetch() 有关守则: url = "https://api.github.com/repos/octocat/Hello-World"; fetch(url).then(function(resp) { return resp.json(); }) .then(function(json){ console.log(json); }); 在localhost调试器ui上运行此命令将返回以下内容,但没

接下来,我遇到了fetch()的问题,我不理解。我还没有找到一篇文章来阐明这一点

fetch()

有关守则:

url = "https://api.github.com/repos/octocat/Hello-World";
fetch(url).then(function(resp) {
  return resp.json();
})
.then(function(json){
  console.log(json);
});
在localhost调试器ui上运行此命令将返回以下内容,但没有
console.log(json)
输出:

Promise {_32: 0, _8: null, _89: Array[0]}
在本机调试ui之外的chrome dev tools控制台上运行此命令:

Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
    Object {id: 1296269, name: "Hello-World", full_name: "octocat/Hello-World", owner: Object, private: false…}
我正在使用教程中所示的最新安装的软件包。我的打包机正在运行
node_modules/react native/packager/launchPackager.command;退出,我可以看到
http://localhost:8081/index.ios.bundle
。为了验证是否发出了https请求,我在本地主机url上运行
fetch()
时监视了本地web服务器日志


有什么想法吗?谢谢

看来我和你遇到了同样的问题

您的问题给了我一些提示,让我理解发生了什么,对于以下代码:

fetch(url, option).
then((res) => {
  const json = res.json();
  console.log(json);
  return json;
}).then(json => {
  console.log(json);
  return json;
});

console.log中的第一个
json
实际上是一个
Promise
。所以它不会打印正确的内容。但是第二个
console.log
将具有正确的
json
,因为
then
函数将解析返回的承诺

不知道为什么,但是
fetch
现在在一个应用程序中为我工作,但仍然不在调试控制台中。