我有这样的反应成分,我创建了一个常量见下文:阵营组件this.variable不渲染
export class MyComponent extends React.Component {
constructor() {
super();
const mytext = 'Some Text';
}
render() {
return (
<div>
{this.mytext}
</div>
);
}
}
这个常量不渲染mytext的,当我使用{} this.mytext
什么我是我做错了?
'const this.mytext ='Some Text';''''mytext}'......! – Jai
mytext的数据类型是const。所以你需要将{this.mytext}改为{mytext} – Ved
@Jai我认为const this this.mytext ='Some Text';是错误的语法。 – Ved