[英]Not getting data from api into the web page, can anyone help me through this where I am getting an error and what can i do to get data
从“反应”导入反应;
/**
应用程序
简单的 react js 获取示例 */ class App extends React.Component {
构造函数(道具){
super(props); this.state = { items: [], isLoaded: false }
}
/**
组件DidMount
从给定的 url 获取 json 对象数组并更新 state。 */ componentDidMount() {
fetch('https://run.mocky.io/v3/8260aa5d-8af8-4cff-999e-6e81b217f0ba').then(res => res.json()).then(json => { this.setState({项目:json, isLoaded: true, }) }).catch((err) => { console.log(err); });
}
/**
使成为
渲染 UI */ render() {
const { isLoaded, items } = this.state;
if (.isLoaded) 返回加载中..;;
返回 (
}
}
导出默认应用程序;
在渲染 function
return (
{
items.clients.map(item => (<span key={item.id}> Name : {item.name}
</span>)
)
}
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.