【发布时间】:2017-04-25 18:42:20
【问题描述】:
根据标题,为什么最初的 this.props 失败了?更实际的是,如果您依赖构造函数中的道具,您如何解决这个问题?例如,我想在我的订阅中引用道具?
class AboutBox extends Component {
static defaultProps = {
title: 'Undefined Product',
}
constructor() {
super();
console.log(this.props.title); //this fails (=> null)
}
render() {
console.log(this.props.title); //this works (=> 'Undefined Product')
return null;
}
}
【问题讨论】:
标签: reactjs meteor ecmascript-6