Vue 解決父組件跳轉(zhuǎn)子路由后當(dāng)前導(dǎo)航active樣式消失問題
舉個(gè)栗子,導(dǎo)航欄如下圖,當(dāng)前新聞資訊的路由是:localhost:8083/#/new,導(dǎo)航欄樣式如圖所示:
隨便挑個(gè)新聞點(diǎn)擊后會(huì)跳轉(zhuǎn)到子路由:localhost:8083/#/new/newDetail,這時(shí)候新聞資訊的主路由style樣式出現(xià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ì)影響到主路由的樣式問題
補(bǔ)充知識(shí):解決element-ui中el-menu組件作為vue-router模式在刷新頁面后default-active屬性與當(dāng)前路由頁面不一致問題的方法
解決辦法是給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樣式消失問題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Java GZip 基于內(nèi)存實(shí)現(xiàn)壓縮和解壓的方法2. SpringBoot+TestNG單元測(cè)試的實(shí)現(xiàn)3. 完美解決vue 中多個(gè)echarts圖表自適應(yīng)的問題4. IntelliJ IDEA設(shè)置默認(rèn)瀏覽器的方法5. Docker容器如何更新打包并上傳到阿里云6. VMware中如何安裝Ubuntu7. Springboot 全局日期格式化處理的實(shí)現(xiàn)8. python 浮點(diǎn)數(shù)四舍五入需要注意的地方9. idea配置jdk的操作方法10. JAMon(Java Application Monitor)備忘記
