欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue+element使用動態(tài)加載路由方式實現(xiàn)三級菜單頁面顯示的操作

 更新時間:2020年08月04日 11:02:36   作者:瘦瘦的小芝芝  
這篇文章主要介紹了vue+element使用動態(tài)加載路由方式實現(xiàn)三級菜單頁面顯示的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

需要用到中間件的方式,這樣就可以實現(xiàn)了我們想要的方式

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()動態(tài)生成三級菜單的問題

標(biāo)題記錄一次vue使用addRouter動態(tài)生成三級菜單欄的問題

1.addRouter()里面需要一個固定格式的數(shù)組:例如

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: 二級路由不能設(shè)置為NULL,必須存在,我設(shè)置的就是Layout(引用自@/layout)

path:路徑最前面不能使用"/"

以上這篇vue+element使用動態(tài)加載路由方式實現(xiàn)三級菜單頁面顯示的操作就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解vue-cli中使用rem,vue自適應(yīng)

    詳解vue-cli中使用rem,vue自適應(yīng)

    這篇文章主要介紹了vue-cli使用rem,vue自適應(yīng),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • 詳解vue掛載到dom上會發(fā)生什么

    詳解vue掛載到dom上會發(fā)生什么

    這篇文章主要介紹了詳解vue掛載到dom上會發(fā)生什么,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • vue移動端彈框組件的實例

    vue移動端彈框組件的實例

    今天小編就為大家分享一篇vue移動端彈框組件的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • Vue數(shù)據(jù)綁定簡析小結(jié)

    Vue數(shù)據(jù)綁定簡析小結(jié)

    這篇文章主要介紹了Vue數(shù)據(jù)綁定簡析小結(jié),本文將從源碼的角度來對Vue響應(yīng)式數(shù)據(jù)中的觀察者模式進(jìn)行簡析。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-05-05
  • 解決element UI 自定義傳參的問題

    解決element UI 自定義傳參的問題

    今天小編就為大家分享一篇解決element UI 自定義傳參的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • Vue函數(shù)式組件-你值得擁有

    Vue函數(shù)式組件-你值得擁有

    這篇文章主要介紹了Vue函數(shù)式組件及vue函數(shù)式組件的優(yōu)缺點,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-05-05
  • vue+axios+element ui 實現(xiàn)全局loading加載示例

    vue+axios+element ui 實現(xiàn)全局loading加載示例

    今天小編就為大家分享一篇vue+axios+element ui 實現(xiàn)全局loading加載示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • 解決vue打包項目后刷新404的問題

    解決vue打包項目后刷新404的問題

    下面小編就為大家整理了一篇解決vue打包項目后刷新404的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • 深入詳解Vue3 ref底層實現(xiàn)原理

    深入詳解Vue3 ref底層實現(xiàn)原理

    隨著現(xiàn)在vue3越來越普及,相應(yīng)的面試題也多了起來。說到vue3的面試題,有一個最經(jīng)典的就是對于實現(xiàn)ref和reactive這兩個方法的底層原理,本文就來和大家簡單講講吧
    2023-04-04
  • Vue實現(xiàn)圖片預(yù)覽功能的詳細(xì)指南

    Vue實現(xiàn)圖片預(yù)覽功能的詳細(xì)指南

    在現(xiàn)代 web 應(yīng)用程序中,圖片預(yù)覽功能提升了用戶體驗,使用戶可以在上傳圖片之前查看圖片內(nèi)容,本文將詳細(xì)介紹如何在 Vue.js 應(yīng)用中實現(xiàn)圖片預(yù)覽功能,包括基本實現(xiàn)、進(jìn)階功能、與 Element UI 的集成、常見優(yōu)化技巧以及與其他庫的結(jié)合使用,需要的朋友可以參考下
    2024-09-09

最新評論