<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為當前項。