我正在使用文档中的 fetch AJAX 示例并获取以下内容:
https://learnwebcode.github.io/json-example/animals-1.json
这是 componentDidMount 部分:
componentDidMount() {
fetch("https://learnwebcode.github.io/json-example/animals-1.json")
.then(res => res.json())
.then(
(result) => {
this.setState({
isLoaded: true,
items: result.items
});
},
我收到“未捕获的类型错误,无法读取未定义的属性映射”
为什么会这样?这是我第一次尝试使用 fetch API。我试图记录响应对象,但返回未定义。
笔的链接在这里:
https://codepen.io/damPop/pen/yQLbxV