vue-element-plus-admin 左侧菜单通过按钮事件添加新菜单,缺少顶部和左侧布局是什么原因?
页面代码:
// 添加菜单
const addMenuItem = () => {
let index = parseInt(Math.random() * 1000000)
const obj = {
path: 'xitong/id=' + index,
component: () => import('@/views/Projectbrowsing/duolianjixitong/xitong/systemTabShow.vue'),
name: 'Xitong' + index,
meta: {
title: tjxtzd.name
}
}
router.addRoute({
path: '/projectbrowsing/duolianjixitong/xitong/id=' + index,
component: () => import('@/views/Projectbrowsing/duolianjixitong/xitong/systemTabShow.vue'),
name: 'Xitong' + index,
meta: {
title: tjxtzd.name
}
})
console.log(router.getRoutes());//数据正确
permissionStore.generateRoutes('addRouteItem',{},obj)
})
}
store/permission.ts文件:
actions: {
generateRoutes(
type: 'admin' | 'test' | 'none' | 'addRouteItem' ,
routers?: AppCustomRouteRecordRaw[] | string[],
routeItem?: {}
): Promise<unknown> {
return new Promise<void>((resolve) => {
let routerMap: AppRouteRecordRaw[] = []
// 直接读取静态路由表
routerMap = cloneDeep(asyncRouterMap)
// 动态路由,404一定要放到最后面
this.addRouters = routerMap.concat([
{
path: '/:path(.*)*',
redirect: '/404',
name: '404Page',
meta: {
hidden: true,
breadcrumb: false
}
}
])
if(type == "addRouteItem"){
// 渲染菜单的所有路由 + 新系统路由
const oldRoutes = cloneDeep(constantRouterMap).concat(routerMap)
oldRoutes.forEach((item) => {
if(item.name == "Projectbrowsing"){
item.children.forEach((itemChildren) => {
if(itemChildren.name == "Duolianjixitong"){
itemChildren.children?.push(routeItem)
}
})
}
})
//console.log(oldRoutes);
this.routers = reactive(oldRoutes)
} else {
// 渲染菜单的所有路由
this.routers = cloneDeep(constantRouterMap).concat(routerMap)
}
resolve()
})
},
打开页面缺少 顶部和左侧布局,