1 回答
TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個(gè)贊
是因?yàn)?JSON 在 它的范圍內(nèi),在它之外不可見(jiàn)。您可能希望將數(shù)據(jù)存儲(chǔ)在組件狀態(tài)中,并將用戶存儲(chǔ)在呈現(xiàn)中。constructor
您可以使用 then .map 來(lái)迭代 中的 JSON 數(shù)據(jù)。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>
);
}
}
添加回答
舉報(bào)
