getData(){ //请求数据函数
fetch('https://www.easy-mock.com/mock/59801fd8a1d30433d84f198c/example/user/all') ///此url地址内有json数据 可模拟使用
.then(res => res.json()) ///解析json数据
.then(data => {
console.log(data)
this.setState({posts: data}) ////赋值到本地数据
})
.catch(e => console.log('错误:', e)) ///请求出错
}
componentWillMount() {
this.getData()
}
react fetch 请求数据
猜你喜欢
转载自blog.csdn.net/weixin_42046201/article/details/80666290
今日推荐
周排行