You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classMyComponentextendsReact.Component{constructor(props){super(props)console.log(this.props)// prints { name: 'John', age: 12 }}}
不带 props 参数
classMyComponentextendsReact.Component{constructor(props){super()console.log(this.props)// prints undefined// but props parameter is still availableconsole.log(props)// prints { name: 'John', age: 42 }}render(){// no difference outside constructorconsole.log(this.props)// prints { name: 'John', age: 42 }}}
The text was updated successfully, but these errors were encountered:
构造函数使用带 props 参数的目的是什么
super()
方法之前,子类构造函数不能使用this
引用.这同样适用于ES6子类.props
参数传递给super()
的主要原因是为了在子构造函数中访问this.props
.带 props 参数
不带 props 参数
The text was updated successfully, but these errors were encountered: