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 请求数据
最新推荐文章于 2025-06-10 11:54:11 发布
