最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

需要用到中間件的方式,這樣就可以實(shí)現(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: '菜單' },
 
    ]
     },
     ]
},

補(bǔ)充知識(shí):Vue使用addRouter()動(dòng)態(tài)生成三級(jí)菜單的問(wèn)題

標(biāo)題記錄一次vue使用addRouter動(dòng)態(tài)生成三級(jí)菜單欄的問(wèn)題

1.addRouter()里面需要一個(gè)固定格式的數(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)
    
   // 三級(jí)菜單生成
   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
}

三級(jí)路由重點(diǎn):

componment: 二級(jí)路由不能設(shè)置為NULL,必須存在,我設(shè)置的就是Layout(引用自@/layout)

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

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

相關(guān)文章

  • 詳細(xì)解讀VUE父子組件的使用

    詳細(xì)解讀VUE父子組件的使用

    這篇文章主要介紹了詳細(xì)解讀VUE父子組件的使用,今天來(lái)講一種子父組件深度耦合的方式,使我們不用額外的創(chuàng)建新的組件,也可以達(dá)到一些效果,下面與你們分享一下
    2023-05-05
  • Vue.js條件渲染和列表渲染以及Vue中key值的內(nèi)部原理

    Vue.js條件渲染和列表渲染以及Vue中key值的內(nèi)部原理

    這篇文章主要介紹了Vue.js條件渲染和列表渲染,以及Vue中key值的內(nèi)部原理,文中有詳細(xì)的代碼示例,感興趣的同學(xué)可以參考閱讀
    2023-04-04
  • 解決vuex數(shù)據(jù)丟失問(wèn)題

    解決vuex數(shù)據(jù)丟失問(wèn)題

    本文主要介紹了解決vuex?數(shù)據(jù)丟失問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • Vue數(shù)據(jù)驅(qū)動(dòng)模擬實(shí)現(xiàn)4

    Vue數(shù)據(jù)驅(qū)動(dòng)模擬實(shí)現(xiàn)4

    這篇文章主要介紹了Vue數(shù)據(jù)驅(qū)動(dòng)模擬實(shí)現(xiàn)的相關(guān)資料,介紹了Array的變異方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • 前端Vue單元測(cè)試入門(mén)教程

    前端Vue單元測(cè)試入門(mén)教程

    單元測(cè)試是用來(lái)測(cè)試項(xiàng)目中的一個(gè)模塊的功能,本文主要介紹了前端Vue單元測(cè)試入門(mén)教程,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • 深入探討Vue3實(shí)現(xiàn)多數(shù)據(jù)變化監(jiān)聽(tīng)的方式

    深入探討Vue3實(shí)現(xiàn)多數(shù)據(jù)變化監(jiān)聽(tīng)的方式

    隨著 Vue 3 的發(fā)布,框架帶來(lái)了更多的新特性和增強(qiáng),其中之一就是 watch 函數(shù)的升級(jí),這一改進(jìn)使得多個(gè)數(shù)據(jù)的變化偵聽(tīng)更加優(yōu)雅和靈活,本文將深入探討 Vue 3 中的 watch 函數(shù),以及如何以更加優(yōu)雅的方式實(shí)現(xiàn)對(duì)多個(gè)數(shù)據(jù)變化的監(jiān)聽(tīng)
    2023-08-08
  • Vue中img的src屬性綁定與static文件夾實(shí)例

    Vue中img的src屬性綁定與static文件夾實(shí)例

    本篇文章中主要介紹了Vue中img的src屬性綁定與static文件夾實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2017-05-05
  • Vue刷新修改頁(yè)面中數(shù)據(jù)的方法

    Vue刷新修改頁(yè)面中數(shù)據(jù)的方法

    今天小編就為大家分享一篇Vue刷新修改頁(yè)面中數(shù)據(jù)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09
  • vue2.0 使用element-ui里的upload組件實(shí)現(xiàn)圖片預(yù)覽效果方法

    vue2.0 使用element-ui里的upload組件實(shí)現(xiàn)圖片預(yù)覽效果方法

    今天小編就為大家分享一篇vue2.0 使用element-ui里的upload組件實(shí)現(xiàn)圖片預(yù)覽效果方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09
  • 前端vue數(shù)組去重的三種方法代碼實(shí)例

    前端vue數(shù)組去重的三種方法代碼實(shí)例

    數(shù)組去重是我面試時(shí)候經(jīng)常會(huì)問(wèn)到應(yīng)聘者的一個(gè)問(wèn)題,所以下面這篇文章主要給大家介紹了關(guān)于前端vue數(shù)組去重的三種方法,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-06-06

最新評(píng)論

塘沽区| 茂名市| 锡林郭勒盟| 广丰县| SHOW| 吴旗县| 金山区| 义马市| 二连浩特市| 城步| 诸暨市| 嘉定区| 临桂县| 呼伦贝尔市| 呼图壁县| 罗江县| 鹤岗市| 简阳市| 东乡| 大足县| 崇礼县| 临邑县| 会东县| 凤翔县| 顺平县| 岢岚县| 北川| 佳木斯市| 龙门县| 金寨县| 溧水县| 昌黎县| 灵台县| 锦州市| 拜城县| 马山县| 萝北县| 温宿县| 株洲市| 苏尼特左旗| 南皮县|