-
// 为属性指定默认值:
Greeting.defaultProps = {
name: 'Stranger'
};
defaultProps
用来确保 this.props.name
在父组件没有特别指定的情况下,有一个初始值
跟
constructor( ) {
} 的作用一 样,给数据赋初值
// 为属性指定默认值:
Greeting.defaultProps = {
name: 'Stranger'
};
defaultProps
用来确保 this.props.name
在父组件没有特别指定的情况下,有一个初始值
跟
constructor( ) {
} 的作用一 样,给数据赋初值