Vue 解决父组件跳转子路由后当前导航active样式消失问题
时间:2020-07-21 13:14:13|栏目:|点击: 次
举个栗子,导航栏如下图,当前新闻资讯的路由是:localhost:8083/#/new,导航栏样式如图所示:

随便挑个新闻点击后会跳转到子路由:localhost:8083/#/new/newDetail,这时候新闻资讯的主路由style样式出现消失的问题,如下图:

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;
}
类名设置为router-link-active,即使是跳转到子路由也不会影响到主路由的样式问题
补充知识:解决element-ui中el-menu组件作为vue-router模式在刷新页面后default-active属性与当前路由页面不一致问题的方法
解决办法是给menu的default-active绑定route.path
形如:
<el-menu :default-active="$route.path" ...>
每次渲染menu都会读当前path 设置为default-active
上一篇:opencv求解区域的内接矩形
栏 目:
本文标题:Vue 解决父组件跳转子路由后当前导航active样式消失问题
本文地址:http://www.codeinn.net/misctech/2402.html






