在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ react在哪個生命周期可以獲得this.props?

react在哪個生命周期可以獲得this.props?

react在哪個生命周期可以獲得this.props?

回答
編輯回答
負(fù)我心

REACT生命周期說明,還沒看到說生命周期內(nèi)無法獲取props的,組件的生命周期就是組件生成到銷毀的整個過程,而props是父組件傳遞的,所以在任何生命周期都可以獲取到父組件傳遞給子組件的props;
需要注意constructor(props)

constructor(props) {
    super(props);
    // 可以使用 props了
}
The constructor for a React component is called before it is mounted. When implementing the constructor for a React.Component subclass, you should call super(props) before any other statement. Otherwise, this.props will be undefined in the constructor, which can lead to bugs.
2018年4月22日 10:10
編輯回答
刮刮樂

除了 constructor 都可以哦,constructorprops 會直接作為參數(shù)傳進(jìn)來。

2018年7月9日 17:21