【发布时间】:2018-12-09 10:50:01
【问题描述】:
在下面的应用程序组件中,我想根据我定义的函数隐藏一个 div,但它会带来一个错误提示
TypeError: 无法读取未定义的属性“setState”
请问哪里出了问题
class Apps extends Component {
constructor(props) {
super(props);
// Don't do this!
this.state = { showing: true };
}
render() {
return (
<div>
<div className="container">
<div style={{ display: (this.state.showing ? 'block' : 'none') }}>
A Single Page web application made with react
</div>
</div>
<div className="buttons">
<a href='' onClick={this.onclick} >Login</a>
<br/>
<a href='' >Signup</a>
<br />
<a href='' >Members</a>
</div>
</div>
);
}
onclick(e){
e.preventDefault();
this.setState({showing: false});
}
}
【问题讨论】:
标签: javascript reactjs ecmascript-6 components