import React, { Component } from 'react'; class Copy extends Component { constructor(props) { super(props); this.state = { current: 1 } } tabFn(index) { this.setState({ current: index }) } componentDidMount() { this.tabFn(1) } clsFn(index, curCls, cls) { let { current } = this.state return current === index ? curCls : cls; } render() { return ( <div> <h1>这是tab选项卡</h1> <div className="tab_con"> <ol> <li onClick={() => { this.tabFn(1) }} className={this.clsFn(1, 'curr', '')}>菜单一</li> <li onClick={() => { this.tabFn(2) }} className={this.clsFn(2, 'curr', '')}> 菜单二</li> <li onClick={() => { this.tabFn(3) }} className={this.clsFn(3, 'curr', '')}> 菜单三</li> </ol> <ul> <li className={this.clsFn(1, 'current', '')}>内容一</li> <li className={this.clsFn(2, 'current', '')}>内容二</li> <li className={this.clsFn(3, 'current', '')}>内容三</li> </ul> </div> </div> ) } } export default Copy;