Ant Design 組件按需加載
參考資料:https://blog.csdn.net/well2049/article/details/78801228
react生命周期
組件優(yōu)化:
props
this.state={
n:0
}
this.setState({
n:100
})
生命周期鉤子:
一快骗、初始化階段
1.設(shè)置默認(rèn)屬性: defaultProps
//設(shè)置默認(rèn)屬性
static defaultProps={
num:100
}
2.構(gòu)造器
constructor() {
super();
//初始狀態(tài)
this.state={
comments:[],
flag:true,
value:3,
n:1
}
}
3.組件加載之前:componentWillMount
4.render:渲染
5.componentDidMount:可以進(jìn)行DOM相關(guān)的操作和獲取后臺(tái)數(shù)據(jù)(即ajax)
二蒜茴、運(yùn)行階段
1.componentWillReceiveProps() 組件接收到屬性時(shí)觸發(fā)
2贮尖、shouldComponentUpdate() 主要用于優(yōu)化組件
> 當(dāng)組件接收到新屬性,或者組件的狀態(tài)發(fā)生改變時(shí)觸發(fā)一睁。組件首次渲染時(shí)并不會(huì)觸發(fā)