import React from 'react'; import ReactDOM from 'react-dom'; function fnFetch(url){ return fetch(url).then(res=>{ if(res.ok){ return res.json(); } }).then(res=>{ return res; }) } class App extends React.Component{ state ={ isLoading:false, data:null }; fetchData = async() =>{ let data = await fnFetch('https://api.github.com/users/asdfds'); this.setState({data}); }; render(){ let {isLoading, data} = this.state; return (

原生fetch交互

{ isLoading?加载中...:
{ data==null?暂无数据...:
  • 名字: {data.name}
  • 公司网址: {data.company}
  • 头像:
}
}
) } } ReactDOM.render( , document.getElementById('root'));