React ant 點(diǎn)擊導(dǎo)航條閃爍問(wèn)題解決
問(wèn)題 : 點(diǎn)擊當(dāng)前位置會(huì)出現(xiàn)閃一下的效果

另一種點(diǎn)擊方式 , 不會(huì)閃

原因 : 沒(méi)有傳遞具體的參數(shù)給點(diǎn)擊事件 , 導(dǎo)致在函數(shù)內(nèi)部無(wú)法準(zhǔn)確判斷要展示哪個(gè)子菜單,可能導(dǎo)致頁(yè)面狀態(tài)的短暫變化,出現(xiàn)閃爍效果
代碼 :
// 左側(cè)子菜單彈出
const showSonMenu = routeKey => {
setDrawerVisible(true)
setCollapsed(!collapsed)
setTitle(!title)
// 根據(jù)點(diǎn)擊的父菜單key來(lái)篩選出對(duì)應(yīng)的子菜單并更新顯示內(nèi)容
const targetRoute = routes.find(route => route.key === routeKey)
// 獲取一級(jí)子菜單和二級(jí)子菜單的 key 值
const openKeys = [targetRoute.key]
if (targetRoute.children && targetRoute.children.length > 0) {
openKeys.push(targetRoute.children[0].key) // 假設(shè)展開(kāi)第一個(gè)二級(jí)子菜單
}
setDefaultOpenKeys(openKeys)
// 更新state或其他方式來(lái)僅顯示目標(biāo)子菜單
setSelectedRoute(targetRoute)
setDrawerVisible(false)
}
// 點(diǎn)擊子菜單
const onClick = e => {
navigate(e.key)
setCurrent(e.key)
}
return (
{drawerVisible ? (
<div className='layoutSon'>
<Menu
onClick={onClick}
defaultOpenKeys={defaultOpenKeys}
selectedKeys={[current]}
mode='inline' //子菜單的樣式是下拉,而不是彈出
theme={Stylebg}
items={selectedRoute ? [selectedRoute] : routes}
/>
</div>
) : null}
// 標(biāo)簽區(qū)域
<Tabs
defaultActiveKey='1'
items={routeList.slice(-1).map((item, index) => {
const id = String(index)
const isLastItem = index === routeList.length - 1
return {
label: (
<div className='breadcrumb-box'>
{index == 0 ? (
<span className='spanIcon'>
<img
src={homeIcon}
alt=''
style={{
width: '17px',
height: '14px',
PointerEvent: 'onne'
}}
/>
</span>
) : null}
{index == 0 ? (
<span
className='location'
onClick={() => showSonMenu(currentPosition)}
>
當(dāng)前位置 : {stairSon}
<span className='slash'>/</span>
</span>
) : null}
<span
onClick={() => {
toRouter(item)
}}
className='breadcrumbTitle'
>
{activeItem?.label}
</span>
</div>
),
key: id
}
})}
)到此這篇關(guān)于React ant 點(diǎn)擊導(dǎo)航條閃爍的文章就介紹到這了,更多相關(guān)React ant 導(dǎo)航條內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
React-router4路由監(jiān)聽(tīng)的實(shí)現(xiàn)
這篇文章主要介紹了React-router4路由監(jiān)聽(tīng)的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
react native仿微信PopupWindow效果的實(shí)例代碼
本篇文章主要介紹了react native仿微信PopupWindow效果的實(shí)例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下2017-08-08
一文帶你掌握React類式組件中setState的應(yīng)用
這篇文章主要為大家詳細(xì)介紹了介紹了React類式組件中setState的三種寫(xiě)法以及簡(jiǎn)單討論下setState?到底是同步的還是異步的,感興趣的可以了解下2024-02-02
React的組件協(xié)同使用實(shí)現(xiàn)方式
這篇文章主要介紹了React的組件協(xié)同使用,文中給大家提到在React開(kāi)發(fā)中,有哪些場(chǎng)景的組件協(xié)同?又如何去實(shí)現(xiàn)組件的協(xié)同使用呢?本文都給大家提到,感興趣的朋友跟隨小編一起看看吧2021-09-09
react.js 獲取真實(shí)的DOM節(jié)點(diǎn)實(shí)例(必看)
下面小編就為大家?guī)?lái)一篇react.js 獲取真實(shí)的DOM節(jié)點(diǎn)實(shí)例(必看)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04
教你使用vscode 搭建react-native開(kāi)發(fā)環(huán)境
本文記錄如何使用vscode打造一個(gè)現(xiàn)代化的react-native開(kāi)發(fā)環(huán)境,旨在提高開(kāi)發(fā)效率和質(zhì)量。本文給大家分享我遇到的問(wèn)題及解決方法,感興趣的朋友跟隨小編一起看看吧2021-07-07
React?Hook中的useState函數(shù)的詳細(xì)解析
Hook 就是 JavaScript 函數(shù),這個(gè)函數(shù)可以幫助你鉤入(hook into) React State以及生命周期等特性,這篇文章主要介紹了React?Hook?useState函數(shù)的詳細(xì)解析的相關(guān)資料,需要的朋友可以參考下2022-10-10

