<!DOCTYPE html><html><head><script src="../build/react.js"></script><script src="../build/react-dom.js"></script><script src="../build/browser.min.js"></script></head><body><div id="example"></div><script type="text/babel">var Hello = React.createClass({getInitialState: function () {return {opacity: 1.0};},componentDidMount: function () {this.timer = setInterval(function () {var opacity = this.state.opacity;opacity -= .05;if (opacity < 0.1) {opacity = 1.0;}this.setState({opacity: opacity});}.bind(this), 100);},render: function () {return (<div style={{opacity: this.state.opacity}}>Hello {this.props.name}</div>);}});ReactDOM.render(<Hello name="world"/>,document.getElementById('example'));</script></body></html>01、组件的生命周期分成三个状态Mounting 已插入真实DOMUpdating 正在被重新渲染Unmounting 已移出真实DOMReact 为每个状态都提供了两种处理函数,will 函数在进入状态之前调用,did 函数在进入状态之后调用三种状态共计五种处理函数componentWillMount()componentDidMount()componentWillUpdate(object nextProps,object nextState)componentDidUpdate(object nextProps,object nextState)componentWillUnmount()另两种特殊处理函数componentWillReceiveProps(object nextProps) 已加载组件收到新的参数时调用shouldComponentUpdate(object nextProps, object nextState) 组件判断是否重新渲染时调用02、上面代码在hello 组件加载以后,通过componentDidMount 方法设置一个定时器,每隔100毫秒,就重新设置组件的透明度,从而引发重新渲染。03、React 中的对象写法style ={{opacity:this.state.opacity}} -->外面一层是javascript语法,里面一个是对象