【发布时间】:2021-01-20 10:27:30
【问题描述】:
如何以正确的方式保存我的对象数组?然后在html中显示它们? 控制台日志可以打印整个数组,但在 html 中的工作方式不同
import React from "react";
import "./style.css";
class App extends React.Component {
constructor() {
super();
this.state = {
quotes: [],
};
}
componentDidMount() {
fetch("https://type.fit/api/quotes")
.then((response) => response.json())
.then((data) => this.setState({ quotes: data }));
}
render() {
console.log(this.state.quotes.text);
return (
<div>
<h1>{this.state.quotes[0].author}</h1>
</div>
);
}
}
export default App;
【问题讨论】:
标签: javascript reactjs react-native fetch