react中tab选项卡切换

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

jsx代码
 

/* 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代码
 

.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;
        }
    }
}

效果图

  • 13
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值