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

原生fetch交互

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