import React from 'react'; import ReactDOM from 'react-dom'; import fetchJsonp from 'fetch-jsonp'; function MyFetchJsonp(url,options){ return fetchJsonp(url,options).then(res=>{ return res.json(); }).then(data=>{ return data; }) } class App extends React.Component{ state ={ isLoading:false, data:[] }; fetchData =async () =>{ let {s} = await MyFetchJsonp('https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=a',{jsonpCallback:'cb'}); this.setState({ data:s }); }; render(){ let {isLoading, data} = this.state; return (

fetch-jsonp跨域取数据

{ isLoading?加载中...:
{ data.length===0?暂无数据...:
    { data.map((val,index)=>
  • {val}
  • ) }
}
}
) } } ReactDOM.render( , document.getElementById('root'));