欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue 解決父組件跳轉(zhuǎn)子路由后當(dāng)前導(dǎo)航active樣式消失問(wèn)題

 更新時(shí)間:2020年07月21日 09:17:56   作者:昔有木如蓋  
這篇文章主要介紹了Vue 解決父組件跳轉(zhuǎn)子路由后當(dāng)前導(dǎo)航active樣式消失問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

舉個(gè)栗子,導(dǎo)航欄如下圖,當(dāng)前新聞資訊的路由是:localhost:8083/#/new,導(dǎo)航欄樣式如圖所示:

隨便挑個(gè)新聞點(diǎn)擊后會(huì)跳轉(zhuǎn)到子路由:localhost:8083/#/new/newDetail,這時(shí)候新聞資訊的主路由style樣式出現(xiàn)消失的問(wèn)題,如下圖:

style代碼:

.router-link-exact-active{
 color: #8fc526!important;
 border-top: 4px solid #8fc526!important;
 }

router.js代碼:

{
  path: '/new',
  name: 'new',
  component: news,
  children: [
  {
   path: '/new/newDetail',
   name: 'newDetail',
   component: newsDetail
  }
  ]
 }

解決方案:

將style方案改成下面即可

.router-link-active{
 color: #8fc526!important;
 border-top: 4px solid #8fc526!important;
}

類名設(shè)置為router-link-active,即使是跳轉(zhuǎn)到子路由也不會(huì)影響到主路由的樣式問(wèn)題

補(bǔ)充知識(shí):解決element-ui中el-menu組件作為vue-router模式在刷新頁(yè)面后default-active屬性與當(dāng)前路由頁(yè)面不一致問(wèn)題的方法

解決辦法是給menu的default-active綁定route.path

形如:

<el-menu :default-active="$route.path" ...>

每次渲染menu都會(huì)讀當(dāng)前path 設(shè)置為default-active

以上這篇Vue 解決父組件跳轉(zhuǎn)子路由后當(dāng)前導(dǎo)航active樣式消失問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論