【发布时间】:2017-08-12 00:53:57
【问题描述】:
我已经制作了一个反应父组件,如果用户单击两个选项之一,则会呈现不同的子组件。
根据选择的选项,我想添加一个active 类。
在下面查看我的代码。
我已经采取了很多方法,但由于我无法弄清楚,所以将它们剥离出来。
class Test extends Component {
constructor(props) {
super(props);
this.state = {
currentView: 'one'
};
this.showOne = this.showOne.bind(this);
this.showTwo = this.showTwo.bind(this);
}
showOne() {
this.setState({
currentView: 'one'
});
}
showTwo() {
this.setState({
currentView: 'two'
});
}
render(){
......
<p className="one" onClick={this.showOne}>One</p>
<p className="two" onClick={this.showTwo}>Two</p>
......
}
}
【问题讨论】:
标签: javascript reactjs