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;
        }
    }
}
相关推荐
清晨Coding1 小时前
为什么用 React Developer Tools 查看组件树这么乱?
前端·react.js
johnjincaaaa1 小时前
猿人学第 18 题「jsvmp 洞察先机」逆向通关实录
javascript·后端
鶴哥只手遮天1 小时前
《Electron 45.2.3 内核解剖》第 4 章 补丁体系:380 个补丁改了什么
前端·electron
FungLeo3 小时前
成为全栈·Vue 管理后台篇·分类树与标签管理:层级数据如何落到管理界面
前端·javascript·vue.js·分类树·naive ui·标签管理·前端数据结构
总要学点什么4 小时前
第108篇:三维特效-图片轨迹线效果——把贴图滚成一串箭头,想用它的本色反而整条消失
开发语言·javascript·ecmascript·gis·webgl·材质·cesium
Lank_M7 小时前
白底都占八成,PNG 为何只在图表页赢过 JPG
前端
张一凡937 小时前
给 Coding Agent 加一道"架构闸门":Jin 是如何做到"先审架构、再写代码、不漂移"的
前端·后端·agent
Linye7 小时前
AI 写的 HTML 原型全是空壳?聊聊真实 DOM 交互避坑
前端·人工智能
ZANE7 小时前
纯前端实现的 PDF 与图片互相转换工具技术实现
前端
Swot7 小时前
SvelteKit Remote Functions 使用指南
前端·后端