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>
);
}
}
添加回答
舉報