elementUI中MENU菜單踩坑
需求:點(diǎn)擊當(dāng)前頁(yè)面的按鈕跳轉(zhuǎn)到首頁(yè),給menu中綁定的default-active賦值
問題:頁(yè)面已經(jīng)跳轉(zhuǎn)過去,可menu選中項(xiàng)根本沒有發(fā)生變化
解決辦法: 直接將當(dāng)前頁(yè)面的路由綁定到default-active上,同時(shí)將index改為當(dāng)前路由,這樣在通過非點(diǎn)擊導(dǎo)航菜單跳轉(zhuǎn)頁(yè)面時(shí)就不需要再來(lái)手動(dòng)改變導(dǎo)航菜單的選中項(xiàng)了,它會(huì)自己選中當(dāng)前頁(yè)面的tab項(xiàng),完美解決!
說明:router屬性很重要,default-active="this.$route.path"也很重要。
<el-menu
? ? ? ? :router="true"
? ? ? ? :default-active="$route.name"
? ? ? ? class="el-menu-demo"
? ? ? ? mode="horizontal"
? ? ? ? @select="select"
? ? ? ? background-color="#545c64"
? ? ? ? text-color="#fff"
? ? ? ? active-text-color="#ffd04b">
? ? ? ? ? ? <el-menu-item :route="{name: 'home'}" index="home">
? ? ? ? ? ? ? ? <template slot="title">
? ? ? ? ? ? ? ? ? ? <Icon type="ios-home"></Icon>
? ? ? ? ? ? ? ? ? ? <span>首頁(yè)</span>
? ? ? ? ? ? ? ? </template>
? ? ? ? ? ? </el-menu-item>
? ? ? ? ? ??
? ? ? ? ? ? <el-menu-item :route="{name: 'article'}" index="article">
? ? ? ? ? ? ? ? <template slot="title">
? ? ? ? ? ? ? ? ? ? <i class="el-icon-location"></i>
? ? ? ? ? ? ? ? ? ? <span>文章</span>
? ? ? ? ? ? ? ? </template>
? ? ? ? ? ? </el-menu-item>
?
? ? ? ? ? ? <el-menu-item :route="{name: 'time'}" index="time">
? ? ? ? ? ? ? ? <template slot="title">
? ? ? ? ? ? ? ? ? ? <i class="el-icon-location"></i>
? ? ? ? ? ? ? ? ? ? <span>時(shí)間軸</span>
? ? ? ? ? ? ? ? </template>
? ? ? ? ? ? </el-menu-item>
? ? ? ? ? ??
? ? ? ? ? ? <el-menu-item :route="{name: 'photo'}" index="photo">
? ? ? ? ? ? ? ? <template slot="title">
? ? ? ? ? ? ? ? ? ? <i class="el-icon-location"></i>
? ? ? ? ? ? ? ? ? ? <span>生活照</span>
? ? ? ? ? ? ? ? </template>
? ? ? ? ? ? </el-menu-item>
? ? ? ? ? ??
? ? ? ? ? ? <el-menu-item :route="{name: 'footprint'}" index="footprint">
? ? ? ? ? ? ? ? <template slot="title">
? ? ? ? ? ? ? ? ? ? <i class="el-icon-location"></i>
? ? ? ? ? ? ? ? ? ? <span>足跡</span>
? ? ? ? ? ? ? ? </template>
? ? ? ? ? ? </el-menu-item>
? ? ? ? ? ??
? ? ? ? ? ? <el-menu-item :route="{name: 'aboutme'}" index="aboutme">
? ? ? ? ? ? ? ? <template slot="title">
? ? ? ? ? ? ? ? ? ? <i class="el-icon-location"></i>
? ? ? ? ? ? ? ? ? ? <span>關(guān)于我</span>
? ? ? ? ? ? ? ? </template>
? ? ? ? ? ? </el-menu-item>
?
? ? ? ? ? ? <el-menu-item :route="{name: 'message'}" index="message">
? ? ? ? ? ? ? ? <template slot="title">
? ? ? ? ? ? ? ? ? ? <i class="el-icon-location"></i>
? ? ? ? ? ? ? ? ? ? <span>留言板</span>
? ? ? ? ? ? ? ? </template>
? ? ? ? ? ? </el-menu-item>
? ? ? ? ? ? <el-menu-item :route="{name: 'manage'}" index="manage">
? ? ? ? ? ? ? ? <template slot="title">
? ? ? ? ? ? ? ? ? ? <i class="el-icon-location"></i>
? ? ? ? ? ? ? ? ? ? <span>后臺(tái)管理</span>
? ? ? ? ? ? ? ? </template>
? ? ? ? ? ? </el-menu-item>
? ? </el-menu>到此這篇關(guān)于elementUI中MENU菜單踩坑的文章就介紹到這了,更多相關(guān)elementUI MENU菜單內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
手把手帶你封裝一個(gè)vue component第三方庫(kù)
這篇文章主要介紹了手把手帶你封裝一個(gè)vue component第三方庫(kù),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-02-02
Vue使用codemirror實(shí)現(xiàn)一個(gè)可插入自定義標(biāo)簽的textarea
這篇文章主要為大家詳細(xì)介紹了Vue如何使用codemirror實(shí)現(xiàn)一個(gè)可插入自定義標(biāo)簽的textarea,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-02-02
簡(jiǎn)化版的vue-router實(shí)現(xiàn)思路詳解
這篇文章主要介紹了簡(jiǎn)化版的vue-router,需要的朋友可以參考下2018-10-10
vue綁定數(shù)字類型 value為數(shù)字的實(shí)例
這篇文章主要介紹了vue綁定數(shù)字類型 value為數(shù)字的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2020-08-08
van-picker組件default-index屬性設(shè)置不生效踩坑及解決
這篇文章主要介紹了van-picker組件default-index屬性設(shè)置不生效踩坑及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01
vue3 + vite + ts 中使用less文件全局變量的操作方法
這篇文章主要介紹了vue3 + vite + ts 中使用less文件全局變量的操作方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-03-03

