这个问题可能是由于你使用了 'exact' 属性来匹配路由路径,而子菜单的路径并不完全匹配父级菜单的路径,因此父级菜单不会高亮。

为了解决这个问题,你可以使用 'exact-active-class' 属性来指定当路由路径完全匹配时要添加的类名。例如:

<el-menu router :default-active='$route.path' exact-active-class='is-active'>
  <el-menu-item index='/'>Home</el-menu-item>
  <el-submenu index='/about'>
    <template slot='title'>About</template>
    <el-menu-item index='/about/company'>Company</el-menu-item>
    <el-menu-item index='/about/team'>Team</el-menu-item>
  </el-submenu>
</el-menu>

在上面的例子中,我们将 'exact-active-class' 设置为 'is-active',这样当路由路径与菜单项的 'index' 属性完全匹配时,该菜单项就会添加 'is-active' 类名,从而高亮父级菜单。


原文地址: http://www.cveoy.top/t/topic/mJHh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录