react ~1.生命周期函数


componentWillMount:function(){}//组件挂载到节点之前执行

componentDidMount:function(){}//节点被加载到指点节点之后执行

componentWillUnmount:function(){}//组件被删除之前执行,可用于执行释放内存,和停定时器等

componentWillUpdate//更新前

componentDidUpdate//通过render渲染到界面之后执行

shouldComponentUpdate:function(){
return true|false//如果返回true,react就会重新调用componentWillUpdate->render->界面重新渲染->componentDidUpdate
} //返回false,就没有然后了

this.setState({
//设置状态state,原state有同样属性就覆盖更新,原state没有,就加入到state中更新state
//当状态更新时,就会调用component,此时可以使用this.props传入其他父页面传入的数据,也可以获取路由传入的数据:this.props.location.state.传入的对象'{}'
})

原文地址:https://www.cnblogs.com/sunshineForFuture/p/10342133.html