react的初始化阶段

来源:互联网 发布:淘宝众筹怎么做 编辑:程序博客网 时间:2024/05/20 03:44
/* * getDefaultProps:         只调用一次,只有组件的第一个实例被初始化的时候才会被调用, *                          实例之间共享引用,处理的是属性 * getInitialState:         初始化每个实例特有的状态,从这个函数开始, *                          每个实例被初始化的时候都会调用它,处理的是状态 *                          使用这个函数必须有return 值 * componentWillMount:      render之前最后一次修改状态的机会 * render:                  只能访问this.state和this.props, *                         【只能有一个顶层组件(但是可以包含多个子组件),不能有多个顶层组件,如:数组】 *                          不允许修改状态和DOM输出 * componentDidMount:       成功render,并渲染完成真实DOM之后触发,可以修改DOM * */ /*查看顺序*/       var HelloWorld=React.createClass({               getDefaultProps:function(){console.log('getDefaultProps',1)},               getInitialState:function(){console.log('getInitialState',2);return null},               componentWillMount:function(){console.log('componentWillMount,3')},               render:function(){                   console.log('render,4')                   return <p>Hello,World</p>               },               componentDidMount:function(){console.log('componentDidMount,5')}       })       React.render(<HelloWorld/>,document.body)
0 0
原创粉丝点击