日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長提供免費(fèi)收錄網(wǎng)站服務(wù),提交前請做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點(diǎn)擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

使用react實(shí)現(xiàn)一個(gè)tab組件的方法:1、通過“export default props => {...}”方式創(chuàng)建TAB button組件;2、通過“tab-group-layout.js”組件來傳“tabIndex”,并設(shè)置默認(rèn)選中的tab效果;3、用react繼承“react.component”組件里的onMouseOver和OnMouseOut方法即可。


怎么使用react實(shí)現(xiàn)一個(gè)tab組件


怎么使用react實(shí)現(xiàn)一個(gè)tab組件?

react寫Tab組件

使用react寫TAB欄組件和對應(yīng)hover事件(背景:在用gatsby開發(fā)頁面時(shí),遇到這樣的組件效果,順便記錄一下)


1、效果

默認(rèn)選中的tab選中效果 和 鼠標(biāo)放上去的hover效果


當(dāng)鼠標(biāo)滑過右側(cè)的tab時(shí),也會有和第一個(gè)一樣的選中效果!

2、tab-button.js 組件

import React from "react"
import { css } from "@emotion/core"
import { Link } from "gatsby"
import jdyStyles from "./container.module.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>
  
)
}

3、tab-group-layout.js 組件

import React from "react"
import { css } from "@emotion/core"
import { Link } from "gatsby"
import ListLink from "../components/tab-button"
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')}>產(chǎn)品介紹</ListLink>
<ListLink to="/about/" selected={(tabIndex==='about')}>成功案列</ListLink>
<ListLink to="/contact/" selected={(tabIndex==='contact')}>服務(wù)支持</ListLink>
<ListLink to="/sweet-pandas-eating-sweets/" selected={(tabIndex==='sweet-pandas-eating-sweets')}>資源中心</ListLink>
</ul>
  
</div>
  
)
}

使用這個(gè)組件傳過來 tabIndex 設(shè)置默認(rèn)選中的tab效果;也可以自己處理展示的邏輯


4、對應(yīng)的css樣式 container.module.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;
}

5、當(dāng)前組件的hover使用的是css樣式控制,也可以用 react繼承 react.component組件里的onMouseOver和OnMouseOut方法來實(shí)現(xiàn)


分享到:
標(biāo)簽:react實(shí)現(xiàn)tab組件 tab組件
用戶無頭像

網(wǎng)友整理

注冊時(shí)間:

網(wǎng)站:5 個(gè)   小程序:0 個(gè)  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨(dú)大挑戰(zhàn)2018-06-03

數(shù)獨(dú)一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學(xué)四六

運(yùn)動步數(shù)有氧達(dá)人2018-06-03

記錄運(yùn)動步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績評定2018-06-03

通用課目體育訓(xùn)練成績評定