1 回答

TA贡献1854条经验 获得超8个赞
是因为 JSON 在 它的范围内,在它之外不可见。您可能希望将数据存储在组件状态中,并将用户存储在呈现中。constructor
您可以使用 then .map 来迭代 中的 JSON 数据。render()
class Example extends Component {
constructor(props) {
super(props);
console.log(props.data);//[{"id":1,"name":"Laravel","created_at":null,"updated_at":null},{"id":2,"name":"Reacts Js","created_at":null,"updated_at":null}]
this.state = {
json:JSON.parse(props.data)
};
}
render() {
return (
<div className="container">
<div className="row justify-content-center">
<div className="col-md-8">
<div className="card">
<div className="card-header">Example Component</div>
{this.state.json.map(i => (
<div>{i.name}</div>
))}
<div className="card-body">I'm an example component!</div>
</div>
</div>
</div>
</div>
);
}
}
添加回答
举报