react中tab选项卡切换

react中tab选项卡切换,直接上代码,简单易懂

jsx代码

javascript 复制代码
/* eslint-disable react-hooks/exhaustive-deps */
import React, { useEffect, useState } from "react";
import DocumentTitle from 'react-document-title'
import styles from './styles.module.less'


// 双旦活动
const Holiday: React.FC<any> = () => {
    const tabList = [
        {
            label:'礼物榜单',
            value:0
        },
        {
            label:'圣诞活动',
            value:1
        },
        {
            label:'元旦活动',
            value:2
        }
    ]
    const [active,setactive] = useState<number>(0)
    const userTop = () => {
        return (
            <div className={styles.userTop}>
                <div>礼物榜单</div>
            </div>        
        )
    }
    const christmas = () => {
        return (
            <div className={styles.explain}>
                <div>圣诞活动</div>
            </div>
        )
    }
    const newYear = () => {
        return (
            <div className={styles.explain}>
                元旦活动
            </div>    
        )
    }
    useEffect(() => {
        
    }, [])


    return (
        <DocumentTitle title='双旦活动'>
            <div className={styles.Holiday}>
                <div className={styles.top}>
                    <div className={styles.btnList} id="btnList">
                        {
                            tabList.map((item:any) => (
                                <div onClick={()=> setactive(item.value)} 
                                key={item.value}
                                className={`${styles.normal} ${active === item.value ? styles.acitve : ''}`}>
                                    {item.label}
                                </div>
                            ))
                        }
                    </div>
                </div>
                <div className={styles.center}>
                    <div className={styles.centerBox}>
                        { active === 0 ? userTop() : active === 1 ? christmas() : newYear()}
                    </div>
                </div>
            </div>
        </DocumentTitle>
    )
}
export default Holiday;

less代码

css 复制代码
.Holiday {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    .top{
        width: 100vw;
        height: 590px;
        background-size: 100%;
        position: relative;
        .btnList{
            width: 100vw;
            padding: 20px 37px;
            box-sizing: border-box;
            position: absolute;
            bottom: 28px;
            height: 120px;
            display: flex;
            justify-content: space-between;
            bottom: 20px;
            .normal{
                &.acitve{
                    background: rgba(1, 50, 82, 1);
                    color: #fff;
                }
                width: 212px;
                height: 80px;
                background: rgba(1, 50, 82, 0.1);
                border-radius: 40px;
                font-size: 30px;
                color: #333;
                display: flex;
                align-items: center;
                justify-content: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
            }
        }
    }
    .center{
        width: 100vw;
        padding: 24px;
        box-sizing: border-box;
        background-size: 100%;
        background-size: cover;
        position: relative;
        .centerBox{
            width: 100%;
            background: #044067;
            border-radius: 20px;
            box-sizing: border-box;
            padding: 30px 28px;
            font-size: 28px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #FFFFFF;
        }
    }
}
相关推荐
天宇&嘘月2 小时前
web第三次作业
前端·javascript·css
小王不会写code2 小时前
axios
前端·javascript·axios
发呆的薇薇°3 小时前
vue3 配置@根路径
前端·vue.js
luckyext3 小时前
HBuilderX中,VUE生成随机数字,vue调用随机数函数
前端·javascript·vue.js·微信小程序·小程序
小小码农(找工作版)3 小时前
JavaScript 前端面试 4(作用域链、this)
前端·javascript·面试
前端没钱4 小时前
前端需要学习 Docker 吗?
前端·学习·docker
前端郭德纲4 小时前
前端自动化部署的极简方案
运维·前端·自动化
海绵宝宝_4 小时前
【HarmonyOS NEXT】获取正式应用签名证书的签名信息
android·前端·华为·harmonyos·鸿蒙·鸿蒙应用开发
码农土豆5 小时前
chrome V3插件开发,调用 chrome.action.setIcon,提示路径找不到
前端·chrome
鱼樱前端5 小时前
深入JavaScript引擎与模块加载机制:从V8原理到模块化实战
前端·javascript