为什么super中传入props,constructor才能使用this.props

来源:1-1 课程导学

wykun

2018-06-21

老师能讲下为什么吗..有点不理解

写回答

2回答

慕瓜8449030

2018-06-22

super算是初始化父类的props 这么理解吧,我们要初始化 才能用,就像日本动画里,天马流星拳都得先喊出口号才使用

0
6
慕瓜8449030
回复
wykun
哈哈 求好评呀
2018-06-25
共6条回复

wykun

提问者

2018-06-22

constructor() {

super()

console.log(this.props)//undefined console.log(props)//error

}
constructor(props) {

super()

console.log(this.props)//undefined console.log(props)//{}

}
constructor(props) {

super(props)

console.log(this.props)//{} console.log(props)//{}

}

(代码在这..)

0
0

Redux+React Router+Node.js全栈开发

全网唯一的React 16+Redux+React Router4实战课程,学到手是你的真本领!

1822 学习 · 750 问题

查看课程