金狮镖局 Design By www.egabc.com
需要用到中间件的方式,这样就可以实现了我们想要的方式
publish-center.vue
<template> <router-view></router-view> </template> <script> export default { } </script>
<el-menu :default-active="$route.path" class="el-menu-vertical-demo el-menus" @open="handleopen" @close="handleclose" @select="handleselect" unique-opened router v-show="!collapsed" > <div class="tools" @click.prevent="collapse"> <i>|||</i> </div> <template v-for="(item,index) in $router.options.routes" v-if="!item.hidden"> <el-submenu :index="index+''" v-if="!item.leaf"> <template slot="title" ><i :class="item.iconCls"></i>{{item.name}}</template> <el-menu-item-group v-for="(child,indexs) in item.children" :index="child.path" :key="child.path" v-if="!child.hidden"> <!-- <el-menu class="xz" v-if="!child.path" :default-active="child.path"> --> <el-submenu :index="child.path" v-if="child.z &&!item.leaf"> <template slot="title" class="child_title"><i :class="child.iconCls"></i>{{child.name}}</template> <el-menu-item v-for="(sun,i) in child.children" :index="sun.path" :key="sun.path" > {{sun.name}} </el-menu-item> </el-submenu> <!-- </el-menu> --> <el-menu-item :index="child.path" v-if="!child.z" :key="child.path"> {{child.name}} </el-menu-item> </el-menu-item-group> <!-- <el-menu-item v-if="child.path">{{child.name}}</el-menu-item> --> <!-- </el-menu-item-group> --> <!-- <el-menu-item v-for="sun in child.children" :index="sun.path" :key="sun.path" v-if="!sun.hidden"> {{sun.name}}</el-menu-item> --> </el-submenu> <el-menu-item v-if="item.leaf&&item.children.length>0" :index="item.children[0].path"><i :class="item.iconCls"></i>{{item.children[0].name}}</el-menu-item> </template> </el-menu>
路由部分:
{ path:'/recordQuery', component:Home, name:'菜单1', iconCls:'el-icon-search', children: [ { path: 'carRecord', z:'1', component: () => import('@/page/publish-center.vue'), name: '菜单2' , children:[{ path: '/carRecord/passRecord', component: passRecord, name: '菜单' }, ] }, ] },
补充知识:Vue使用addRouter()动态生成三级菜单的问题
标题记录一次vue使用addRouter动态生成三级菜单栏的问题
1.addRouter()里面需要一个固定格式的数组:例如
import { asyncRoutes, constantRoutes } from '@/router' /* Layout */ import Layout from '@/layout' /** * Use meta.role to determine if the current user has permission * @param roles * @param route */ function hasPermission(roles, route) { if (route.meta && route.meta.roles) { return roles.some(role => route.meta.roles.includes(role)) } else { return true } } /** * Filter asynchronous routing tables by recursion * @param routes asyncRoutes * @param roles */ export function filterAsyncRoutes(routes, roles, parentModules) { const res = [] parentModules.forEach(parentModule => { var tmp = {} tmp.path = parentModule.parentTargetUrl tmp.component = Layout tmp.name = parentModule.parentTargetUrl.substr(1) tmp.meta = {} tmp.meta.title = parentModule.parentModuleName tmp.meta.icon = 'dashboard' tmp.meta.roles = roles tmp.children = [] parentModule.modules.forEach(module => { // XXXListPage var childrenTmpListPage = {} var childrenTmpEditPage = {} //childrenTmpListPage.path = '/' + module.targetName + 'ListPage' childrenTmpListPage.name = module.targetName + 'ListPage' childrenTmpListPage.meta = {} childrenTmpListPage.meta.title = module.moduleName childrenTmpListPage.meta.icon = 'dashboard' childrenTmpListPage.meta.roles = roles //childrenTmpListPage.component = resolve => require(['@/page/' + module.targetName.charAt(0).toUpperCase() + module.targetName.slice(1) + '/list_page'], resolve) childrenTmpListPage.path = '/' + module.targetName + 'ListPage' if(module.childrenModules != null && module.childrenModules != undefined && module.childrenModules != ""){ childrenTmpListPage.component = Layout }else{ childrenTmpListPage.component = resolve => require(['@/page/' + module.targetName.charAt(0).toUpperCase() + module.targetName.slice(1) + '/list_page'], resolve) } childrenTmpListPage.children = [] // XXXEditPage // childrenTmpEditPage.path = '/' + module.targetName + 'EditPage' // childrenTmpEditPage.name = module.targetName + 'EditPage' // childrenTmpEditPage.meta = {} // childrenTmpEditPage.meta.title = module.moduleName // childrenTmpEditPage.meta.icon = 'dashboard' // childrenTmpEditPage.meta.roles = roles // childrenTmpEditPage.hidden = true // childrenTmpEditPage.component = resolve => require(['@/page/' + module.targetName.charAt(0).toUpperCase() + module.targetName.slice(1) + '/edit_page'], resolve) // 三级菜单生成 var roleChildren = roles if(module.childrenModules != null && module.childrenModules != undefined && module.childrenModules != ""){ module.childrenModules.forEach(module =>{ var children2TmpListPage = {} var children2TmpEditPage = {} // childrenTmpListPage.path children2TmpListPage.path = module.targetName + 'ListPage' alert(children2TmpListPage.path) children2TmpListPage.name = module.targetName + 'ListPage' children2TmpListPage.meta = {} children2TmpListPage.meta.title = module.moduleName children2TmpListPage.meta.icon = 'dashboard' children2TmpListPage.meta.roles = roleChildren children2TmpListPage.component = resolve => require(['@/page/' + module.targetName.charAt(0).toUpperCase() + module.targetName.slice(1) + '/list_page'], resolve) console.log('@/page/' + module.targetName.charAt(0).toUpperCase() + module.targetName.slice(1) + '/list_page') childrenTmpListPage.children.push(children2TmpListPage) }) } tmp.children.push(childrenTmpListPage) // tmp.children.push(childrenTmpEditPage) }) res.push(tmp) }) console.log(res) return res } const state = { routes: [], addRoutes: [] } const mutations = { SET_ROUTES: (state, routes) => { state.addRoutes = routes state.routes = constantRoutes.concat(routes) } } const actions = { generateRoutes({ commit }, obj) { return new Promise(resolve => { let accessedRoutes = filterAsyncRoutes(asyncRoutes, obj.roles, obj.parentModules) commit('SET_ROUTES', accessedRoutes) resolve(accessedRoutes) }) } } export default { namespaced: true, state, mutations, actions }
三级路由重点:
componment: 二级路由不能设置为NULL,必须存在,我设置的就是Layout(引用自@/layout)
path:路径最前面不能使用"/"
以上这篇vue+element使用动态加载路由方式实现三级菜单页面显示的操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
金狮镖局 Design By www.egabc.com
金狮镖局
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
金狮镖局 Design By www.egabc.com
暂无vue+element使用动态加载路由方式实现三级菜单页面显示的操作的评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年11月19日
2024年11月19日
- 王杰《这场游戏那场梦》 台湾华纳首版 [WAV+CUE][1G]
- 群星2005-《影视红声》2CD香港首版[WAV+CUE]
- 群星2017《聆听中国.风华国乐》试音碟[WAV+CUE]
- 群星2016-《环球词选.潘源良》环球[WAV+CUE]
- 张惠妹《爱的力量》10年情歌最精选 2CD[WAV+CUE][1.1G]
- 群星2009《LOVE TV情歌精选VOL.2》香港首版[WAV+CUE][1.1G]
- 周慧敏《玉女天后》原音母版1:1直刻[WAV+CUE][1G]
- 李国祥.1994-心倦(EP)(2015新世纪复刻版)【嘉音】【WAV+CUE】
- 杨采妮.1993-爱的感觉【EMI百代】【WAV+CUE】
- 潘盈.1993-旧情绵绵【名将】【WAV+CUE】
- 西野カナ《Loveit》24-96[FLAC]
- 群星2016-《环球词选周礼茂》[环球][WAV+CUE]
- XSProject-Бочкабасколбаср(TheBestOf)(LimitedEdition)[2024][WAV]
- 群星1997 《国语卖座舞曲大碟》引进版[WAV+CUE][1.1G]
- 汪峰 白金超精选专辑《笑着哭》[WAV+CUE][1G]