因此,这个问题非常简单.为什么这会起作用:
fetch("https://api.github.com/users/vampaynani/repos")
.then((res) => res.json())
.then((repos) => {
console.log(repos);
this.setState({ repos });
});
但这并不意味着:
fetch("https://api.github.com/users/vampaynani/repos").then((repos) => {
var r = repos.json();
this.setState({ repos: r });
});
这是它的Sandbox 链接:SandBox
也许我的理解是错误的,但在我看来,这些都是在做同样的事情.