react+antd 选项卡切换


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:
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM