
刚入门react的新手如何利用react做一个tab功能,下面web建站小编给大家介绍一下功能的实现方法。
1、tab.js 组件
import React from "react"
import { css } from "@emotion/core"
import { Link } from "gatsby"
import jdyStyles from "./container.css"
// TAB button 组件
export default props => {
return (
<li css={css`font-size: 18px;margin-left:18px;margin-right: 18px;display:flex;flex-direction: column;align-items:center;justify-content:center`} >
<Link css={css`font-size: 18px;padding: 20px 12px;`}
className={ (props.selected?jdyStyles.header_hover_default:jdyStyles.header_hover) } to={props.to}>
{props.children}
</Link>
</li>
)
}
2、tab-layout.js 组件
import React from "react"
import { css } from "@emotion/core"
import { Link } from "gatsby"
import ListLink from "../components/tab"
import RegisterButton from "../components/round-button"
export default ({ tabIndex }) => {
return (
<div>
{/* tab */}
<ul style={{ listStyle: `none`, float: `right` }} css={css`display: flex;justify-content: space-between;align-items: center;`}>
<ListLink to="/official-site/" selected={(tabIndex==='official-site')}>产品介绍</ListLink>
<ListLink to="/about/" selected={(tabIndex==='about')}>成功案列</ListLink>
<ListLink to="/contact/" selected={(tabIndex==='contact')}>服务支持</ListLink>
<ListLink to="/sweet-pandas-eating-sweets/" selected={(tabIndex==='sweet-pandas-eating-sweets')}>资源中心</ListLink>
</ul>
</div>
)
}
3、container.css
.header_hover{
color: #333;
}
.header_hover_default{
color: #0084ff!important;
border-top: 3px solid #0084ff;
}
.header_hover:hover{
color: #0084ff!important;
border-top: 3px solid #0084ff;
}
上面是“利用react做一个tab功能(组件)”的全面内容,想了解更多关于 reactjs 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_2554.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

帝国cms7.0内容页模板实现多背景tag标签
Tinkercad官网:一个零基础的3D建模教学网站
汇率换算器:收录全球160+个国家及地区的实时汇率换算
LeetTools