我有一个类似于这样的JSON数据,
我想使用这个JSON数据,然后在React JS中将数据显示在表格中。
以下是我如何从JSON文件中显示数据的方式。
如何使用ReactJS从URL加载JSON并在表格中显示它?
我想使用这个JSON数据,然后在React JS中将数据显示在表格中。
以下是我如何从JSON文件中显示数据的方式。
import React, { Component } from 'react';
import data from './data.json';
class App extends Component {
render() {
return (
<ul>
{
data.map(function(movie){
return <li>{movie.id} - {movie.title}</li>;
})
}
</ul>
);
}
}
export default App;
如何使用ReactJS从URL加载JSON并在表格中显示它?
componentDidMount()
方法是获取数据的首选生命周期方法。从React 16.3开始,componentWillMount()
方法将以UNSAFE_
作为前缀,并且很可能会在未来的React版本中被删除。请参阅https://reactjs.org/docs/react-component.html#unsafe_componentwillmount。 - trixnfetch
,那么你的浏览器不支持它。你应该使用我列出的其中一种替代方案。在我的答案中有两个库的链接。 - Phillip