vue+element는 동적 로드 루트를 사용하여 3단계 메뉴 페이지 표시 동작을 실현합니다

중간부품이 필요한 방식, 이렇게 하면 우리가 원하는 방식을 실현할 수 있다
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()를 사용하여 3단계 메뉴를 동적으로 생성하는 문제
제목 기록 vue가addRouter를 사용하여 3단계 메뉴 표시줄을 동적으로 생성하는 문제
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
}
3단계 라우팅 포인트:
componment: 2단계 루트는 NULL로 설정할 수 없습니다. 반드시 존재해야 합니다. 제가 설정한 것은 Layout입니다. (@/layout 참조)
path: 경로 맨 앞에는 "/"를 사용할 수 없습니다.
상기 vue+element는 동적 로드 루트 방식을 사용하여 3급 메뉴 페이지의 표시를 실현하는 작업은 바로 편집자가 여러분에게 공유한 모든 내용입니다. 참고도 해주시고 저희를 많이 사랑해 주시기 바랍니다.

좋은 웹페이지 즐겨찾기