var Hello = React.createClass({
getInitialState:function(){
alert('init');
return{
opacity:1.0,
fontSize:'12px'
};
},
render:function(){
//return <div style={this.state}>Hello {this.props.name}</div>
return <div style={{opactity:this.state.opactity,fontSize:this.state.fontSize}}>Hello {this.props.name}</div>
},
componentWillMount:function(){
alert('will');
},
componentDidMount:function(){
alert('did);
var _self = this;
window.setTimeout(function(){
_self.setState({
opacity: 0.5,
fontSize: '44px'
});
},1000);
}
});
React.render(<Hello name="Word"/>,document.getElementById('container'));
React组件的生命周期
最新推荐文章于 2024-09-25 10:46:15 发布