rt
var per = React.createClass({
getInitialState:function(){
return (styles = {
width:'100%',
height:'100%',
background:'red',
position:'fixed'
})
},
componentWillMount:function(){
alert('ok')
},
render:function(){
return (
{this.props}
)
},
componentDidMount:function(){
alert('OK')
}
});
React.render(
,
document.querySelector('.wrap')
componentWillMount与componentDidMount这两个函数的作用是什么?还望大家赐教
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
will是在render之前调用,did是在render之后调用,具体有什么用要看你在function里面怎么写。比如,will里面请求数据,did在告诉服务器render已经完成