"在构造函数调用 super 并将 props 作为参数传入的作用是啥?"

在构造函数调用 super 并将 props 作为参数传入的作用是啥?

在调用 super() 方法之前,子类构造函数无法使用 this 引用,ES6 子类也是如此。将 props 参数传递给 super() 调用的主要原因是在子构造函数中能够通过 this.props 来获取传入的 props

PS:写作不易,如要转裁,请标明转载出处。
登录
注册
回顶部