如何在react中实现一个table切换?

废话不说,直接贴代码,供新手参考

export default class TabComponent extends Component {
constructor(props){
super(props);
this.state = {

    };
}
render(){
    return (
        <TabController>
            <div name="one">
                第一部分
            </div>
            <div name="two">
                第二部分
            </div>
            <div name="three">
                第三部分
            </div>
        </TabController>
    );
}

}

上面是一个组件

constructor(props) {
super(props);
this.state = {
coutype: 0
}
}
itemNav = (index) => {
return index === this.state.coutype ? 'active' : '';
}

    { this.state.couponBar.map((element,index) => { return (
  • { this.setState({ coutype: index }) } } className={ this.itemNav(index) } key={index}>{ element }
  • ) }) }

猜你喜欢

转载自www.cnblogs.com/panax/p/9240090.html