componentDidMount()
componentDidMount() 方法会在组件已经被渲染到 DOM 中后运行
请求一般在此方法中发送
componentWillUnmount()
componentWillUnmount() 方法会在组件被删除时运行(删除前)
componentDidUpdate()
componentDidUpdate() 会在更新后 会被立即调用。首次渲染不会执行此方法。
shouldComponentUpdate(nextProps, nextState)
在reder()之前执行,如果返回false,则后续render不会执行,true则执行
作用: 可以阻止一些不必要的渲染来提高效率
shouldComponentUpdate(nextProps, nextState){
//做对象比较是要注意
return nextProps.XXX != this.props.XXX;
//或者是state
//return nextState.XXX != this.state.XXX;
}
如果使用PureComponent也可以实现这种优化
531

被折叠的 条评论
为什么被折叠?



