您的当前位置:首页正文

react 安装ajax,4. React-Ajax请求

2024-11-27 来源:个人技术集锦

## React

~~~

~~~

~~~

{this.state.img}

class Clock extends React.Component{

constructor(props){

super(props);

this.state = {

msg:"hello world",

img:"",

title:""

};

}

~~~

~~~

render(){

return (

{this.state.title}

)

}

~~~

~~~

componentDidMount(){

var url = "https://douban.uieee.com/v2/movie/top250";

$.ajax({

url,

type:"get",

dataType:"jsonp",

success: res=> {

var subjects = res.subjects[0];

var img = subjects.images.small;

var title = subjects.title;

this.setState(()=>{

return {

img,

title

}

})

}

})

}

}

~~~

~~~

ReactDOM.render(

,

document.getElementById('example')

);

~~~

显示全文