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

Posted Panax

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在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 }
  • ) }) }

以上是关于如何在react中实现一个table切换?的主要内容,如果未能解决你的问题,请参考以下文章