index.js:

import React from 'react';
import ReactDOM from 'react-dom';
import CardSecond from './CardSecond';
import './index.css';

ReactDOM.render(
<div>
<CardSecond />
</div>,
document.getElementById('root')
);
 
 
CardSecond.js:
 
import React from 'react';
import 'antd/dist/antd.css';
import { Card } from 'antd';

const tabListNoTitle = [{
key: 'ha',
tab: 'haha',
}, {
key: 'hei',
tab: 'heihei',
}, {
key: 'he',
tab: 'hehe',
}, {
key: 'ke',
tab: 'keke',
}, {
key: 'de',
tab: 'dede',
}];

const contentListNoTitle = {
ha: <p>haha</p>,
hei: <p>heihei</p>,
he: <p>hehe</p>,
ke: <p>keke</p>,
de: <p>dede</p>,
};

class TabsCard extends React.Component {
state = {
noTitleKey: 'hei',
}

onTabChange = (key, type) => {
console.log(key, type);
this.setState({ [type]: key });
}

render() {
return (
<div>
<Card
style={{ width: '100%' }}
tabList={tabListNoTitle}
activeTabKey={this.state.noTitleKey}
onTabChange={(key) => { this.onTabChange(key, 'noTitleKey'); }}
>
{contentListNoTitle[this.state.noTitleKey]}
</Card>
</div>
);
}
}

export default TabsCard
 
 
 
#result:
 

react+antd 选项卡切换

相关文章:

  • 2017-12-13
  • 2022-12-23
  • 2018-03-20
  • 2021-11-08
  • 2022-02-01
  • 2021-08-15
  • 2022-02-27
  • 2021-06-08
猜你喜欢
  • 2021-09-20
  • 2021-06-05
  • 2021-05-03
  • 2022-12-23
  • 2022-12-23
  • 2021-05-01
相关资源
相似解决方案