vue-element-plus-admin 左侧菜单通过按钮事件添加新菜单,缺少顶部和左侧布局是什么原因?

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()
      })
    },

image.png

打开页面缺少 顶部和左侧布局,
image.png

阅读 2.5k
1 个回答
//添加事件
const add = () =>{
  permissionStore.generateRoutes2([
    {
      path: 'Test',
      name: 'Test',
      component: function(){return import('@/views/Test/Menu2.vue')},
      meta: {
        title: '测试'
      }
    }
  ])

  permissionStore.getRouters.forEach((route) => {
    if (route.name === "Level") {
      router.addRoute(route as any)//动态添加可访问路由表
    }
  })
}
    //添加 系统新菜单
    generateRoutes2(routers: any[]) {
      return new Promise<void>((resolve) => {
        const oldRouters = cloneDeep(this.routers)
        oldRouters.map((item) => {
          if(item.name === "Level" && item.children){
            item.children.map((item1) => {
              if(item1.name === "Menu1" && item1.children){
                item1.children = item1.children.concat(routers)
              }
            })
            //item.children = item.children.concat(routers)
          }
        })
        this.routers = cloneDeep(oldRouters)
        resolve()
      })
    },
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏