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;
        }
    }
}
相关推荐
Revolution6110 小时前
React 组件重新渲染时,到底重新执行了什么
前端·react.js·面试
林焱_RPAAI10 小时前
影刀RPA技术深度:CSS选择器高级实战指南——伪类属性选择器与性能对比完全解析
vue.js·react.js
用户21816970493011 小时前
Flutter(四)Dart语法 空安全 运算符 流程控制
前端
许彰午11 小时前
政务督办的分合模式:主办协办的并发审批
前端·javascript·政务
用户693717500138411 小时前
AI时代,程序员该往哪走?
前端·后端
ttwuai11 小时前
GoFrame 后台日志清空失败:无 WHERE 删除为什么被拦住
前端·golang
易筋紫容11 小时前
创建型模式:对象的诞生艺术
开发语言·前端·javascript
半句唐诗12 小时前
我是如何通过 Access Token 成功发布第一个 npm 包的
前端·npm·node.js
程序员黑豆12 小时前
鸿蒙应用开发:@Provider 与 @Consumer 跨组件双向同步详解
前端·harmonyos
paopaokaka_luck12 小时前
基于springboot3+vue3的智能文库平台(AI智能搜索、AI智能汇总、实时在线状态展示、多格式文档预览与富文本编辑、Echarts图形化分析)
前端·网络·spring boot·网络协议·echarts