React手寫(xiě)tab切換問(wèn)題

父文件
import React, { useState } from 'react';
// import Module1 from './Module1';
// import Module2 from './Module2';
// import Module3 from './Module3';
// import Module4 from './Module4';
import HeaderTtabs, { tagType } from '@/components/Task/Tree/Common/component/TabsContent/ListContent/HeadTabs';
import { divide } from 'lodash';
export default function (props: any) {
const tabsList: tagType[] = [
{ name: 'xxx況' },
{ name: '培育xxxxx', disabled: false },
{ name: '關(guān)xxxx', disabled: false },
{ name: '科xxxx', disabled: false },
{ name: '人xxxx', disabled: false },
];
const [checkedTag, setCheckedTag] = useState(tabsList[0])
return (<div>
<HeaderTtabs tabsList={tabsList} checkedTag={checkedTag} setCheckedMenu={(tab) => setCheckedTag(tab)} />
<div className={`pt5 px20 pb20`}>
{checkedTag.name === tabsList[0].name && <div>11</div>}
{checkedTag.name === tabsList[1].name && <div>22</div>}
{checkedTag.name === tabsList[2].name && <div>33</div>}
{checkedTag.name === tabsList[3].name && <div>44</div>}
{checkedTag.name === tabsList[4].name && <div>55</div>}
{/* {checkedTag.name === tabsList[0].name && <Module1 />}
{checkedTag.name === tabsList[1].name && <Module2 />}
{checkedTag.name === tabsList[2].name && <Module3 />}
{checkedTag.name === tabsList[3].name && <Module4 />} */}
</div>
</div>);
}
子文件
import style from './index.scss';
import React from 'react';
import { message } from 'antd';
// 標(biāo)簽類(lèi)型
export type tagType = {
name: string, // 標(biāo)簽名稱(chēng),唯一
disabled?: boolean // 是否禁用
}
/**
* 子頁(yè)面 tab 欄
* @param props
*/
export default function(props: {
tabsList: tagType[], // 標(biāo)簽列表
checkedTag: tagType, // 當(dāng)前選中的標(biāo)簽
setCheckedMenu: (menu: tagType) => void // 標(biāo)簽點(diǎn)擊回調(diào)
}) {
const {tabsList, checkedTag, setCheckedMenu} = props
const setCheck = (menu: tagType) => {
if (menu.disabled) {
message.warning('功能暫未開(kāi)放');
return
}
setCheckedMenu(menu)
}
return (<div className={`${style.tag_area} ${style.epidemic_area}`}>
{
tabsList.map((item) => (
<div className={`${style.tag} ${checkedTag.name === item.name ? style.checked : ''} ${style.epidemic}`} key={item.name} onClick={() => setCheck(item)}>
{item.name}
</div>
))
}
</div>)
}
子文件-tab樣式:

.tag_area {
display: flex;
align-items: center;
justify-content: center;
margin-top: -20px;
background-color: #fff;
margin-bottom: 20px;
@media only screen and (max-width: 768px) {
& {
margin-top: 10px;
}
}
}
.tag {
// flex: 1;
// margin: 0 15px;
min-width: 130px;
padding: 10px;
display: flex;
align-items: center;
justify-content: center;
background-color: #fff;
height: 50px;
color: #333;
cursor: pointer;
transition: .3s all;
// box-shadow: 5px 3px 4px #999;
font-size: 18px;
// border-radius: 10px;
border-radius: 6px 6px 0px 0px;
@media only screen and (max-width: 768px) {
& {
font-size: 14px;
margin: 0 5px;
min-height: 30px;
text-align: center;
padding: 5px;
}
}
&.checked {
color: #fff;
background-color: #1E9FFF;
}
&:hover {
color: #fff;
background-color: #1E9FFF;
}
}
// 浙里防疫 四個(gè)tab樣式
.epidemic_area{
justify-content: left;
margin: 10px 20px;
padding:10px;
}
.epidemic{
margin:0 10px;
width: 200px;
background: rgba(20, 146, 255, 0.1);
border: 1px solid #1492FF;
box-sizing: border-box;
border-radius: 4px;
height: 44px;
}
到此這篇關(guān)于React手寫(xiě)tab切換的文章就介紹到這了,更多相關(guān)React tab切換內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
react-native 封裝視頻播放器react-native-video的使用
本文主要介紹了react-native 封裝視頻播放器react-native-video的使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01
ReactHook使用useState更新變量后,如何拿到變量更新后的值
這篇文章主要介紹了ReactHook使用useState更新變量后,如何拿到變量更新后的值問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03
React入門(mén)教程之Hello World以及環(huán)境搭建詳解
Facebook 為了開(kāi)發(fā)一套更好更適合自己的JavaScript MVC 框架,所以產(chǎn)生了react。后來(lái)反響很好,所以于2013年5月開(kāi)源。下面這篇文章主要給大家介紹了關(guān)于React入門(mén)教程之Hello World以及環(huán)境搭建的相關(guān)資料,需要的朋友可以參考借鑒。2017-07-07
React中使用setInterval函數(shù)的實(shí)例
這篇文章主要介紹了React中使用setInterval函數(shù)的實(shí)例,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04
詳解關(guān)于react-redux中的connect用法介紹及原理解析
本篇文章主要介紹了詳解關(guān)于react-redux中的connect用法介紹及原理解析,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2017-09-09
淺析JS中什么是自定義react數(shù)據(jù)驗(yàn)證組件
我們?cè)谧銮岸吮韱翁峤粫r(shí),經(jīng)常會(huì)遇到要對(duì)表單中的數(shù)據(jù)進(jìn)行校驗(yàn)的問(wèn)題。這篇文章主要介紹了js中什么是自定義react數(shù)據(jù)驗(yàn)證組件,需要的朋友可以參考下2018-10-10
react實(shí)現(xiàn)路由動(dòng)畫(huà)跳轉(zhuǎn)功能
這篇文章主要介紹了react路由動(dòng)畫(huà)跳轉(zhuǎn)功能,大概思路是下載第三方庫(kù)?引用,創(chuàng)建css文件引用,想要實(shí)現(xiàn)跳轉(zhuǎn)動(dòng)畫(huà)功能,就在那個(gè)組件的根節(jié)點(diǎn)綁定classname屬性即可,在跳轉(zhuǎn)的時(shí)候即可實(shí)現(xiàn),需要的朋友可以參考下2023-10-10
react ant Design手動(dòng)設(shè)置表單的值操作
這篇文章主要介紹了react ant Design手動(dòng)設(shè)置表單的值操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10

