在Vue2.0中使用ElementUI时,如果你遇到了在使用<el-menu>组件进行路由页面跳转时遇到子路径不显示的问题,可能是因为你的<el-menu-item>的index属性没有正确对应你的路由器中的路径。
确保你的<el-menu-item>的index属性与你的路由路径完全匹配,包括子路径。例如,如果你有一个子路径/user/profile,确保<el-menu-item>的index属性设置为'/user/profile'。
以下是一个简单的例子:
<template>
  <el-menu :default-active="onActiveMenu">
    <el-menu-item index="/">首页</el-menu-item>
    <el-menu-item index="/user">用户管理</el-menu-item>
    <el-submenu index="/user">
      <template slot="title">用户</template>
      <el-menu-item index="/user/profile">个人信息</el-menu-item>
      <el-menu-item index="/user/settings">设置</el-menu-item>
    </el-submenu>
  </el-menu>
</template>
 
<script>
export default {
  data() {
    return {
      // 假设当前路由为/user/profile
      currentPath: this.$route.path
    };
  },
  computed: {
    onActiveMenu() {
      // 根据当前路径动态设置激活菜单项
      return this.currentPath;
    }
  }
};
</script>在这个例子中,onActiveMenu计算属性会根据当前的路由路径来设置default-active属性,从而激活相应的菜单项。确保index属性与你的路由路径完全匹配。如果你的子路由是动态路由参数,确保index也包含了相应的参数占位符。