Javascript 从ReactJS中的属性初始化字段
我很难弄清楚如何基于属性正确创建类字段Javascript 从ReactJS中的属性初始化字段,javascript,reactjs,class-fields,Javascript,Reactjs,Class Fields,我很难弄清楚如何基于属性正确创建类字段 class Example extends Component { example_titles = props.titles; // ... } 导致 Line 7: 'props' is not defined no-undef 我在另一个100%正常工作的文件中调用该类,除非我使用以下调用添加该标记 我使用巴别塔的第二阶段来消除构造函数。我知道如何使用构造函数来实现这一点,但如果没有他们,我很难理解这一点 您可以使用this.pro
class Example extends Component {
example_titles = props.titles;
// ...
}
导致
Line 7: 'props' is not defined no-undef
我在另一个100%正常工作的文件中调用该类,除非我使用以下调用添加该标记
我使用巴别塔的第二阶段来消除构造函数。我知道如何使用构造函数来实现这一点,但如果没有他们,我很难理解这一点 您可以使用
this.props
访问类属性中的道具
类示例扩展了React.Component{
示例_titles=this.props.titles;
render(){
返回(
{this.example_titles.map((title,index)=>(
{title}
))}
);
}
}
ReactDOM.render(
,
document.getElementById(“根”)
);代码>