element---------------el-menu组件_实现路由跳转及当前项的设置

<el-menu router :default-active="$route.path" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" theme="dark">  
    <el-submenu index="1">  
        <template slot="title">  
            <i class="el-icon-location"></i>  
            <span>用户信息</span>  
        </template>  
        <el-menu-item-group>  
            <el-menu-item index="/user/account">账号信息</el-menu-item>  
            <el-menu-item index="/user/password">修改密码</el-menu-item>  
    </el-submenu>  
    <el-submenu index="2">  
            <template slot="title">  
            <i class="el-icon-location"></i>  
            <span>公司信息</span>  
        </template>  
        <el-menu-item-group>  
            <el-menu-item index="/company/userManager">用户管理</el-menu-item>  
            <el-menu-item index="/company/editUser">添加/编辑用户</el-menu-item>  
        </el-menu-item-group>  
        </el-submenu>  
</el-menu>

1.要实现路由跳转,先要在el-menu标签上添加router属性,然后只要在每个el-menu-item标签内的index属性设置一下url即可实现点击el-menu-item实现路由跳转。

2.导航当前项,在el-menu标签中绑定  :default-active="$route.path",注意是绑定属性,不要忘了加“:”,当$route.path等于el-menu-item标签中的index属性值时则该item为当前项。

猜你喜欢

转载自www.cnblogs.com/dianzan/p/11388278.html