rt
var Diver = React.createClass({
getInitialState:function(){
return (styles = {
width:'100%',
height:'100%',
background:'red',
position:'fixed'
})
},
componentWillMount:function(){
alert('ok')
},
render:function(){
return (
<div className = 'container' style={this.state}>{this.props}</div>
)
},
componentDidMount:function(){
alert('OK')
}
});
React.render(
<Diver name = 'myname'/>,
document.querySelector('.wrap')
componentWillMount与componentDidMount这两个函数的作用是什么?还望大家赐教
will是在render之前调用,did是在render之后调用,具体有什么用要看你在function里面怎么写。比如,will里面请求数据,did在告诉服务器render已经完成