Vue 配合eiement動(dòng)態(tài)路由,權(quán)限驗(yàn)證的方法
1.要實(shí)現(xiàn)動(dòng)態(tài)路由,只需要在main.js中將所有路由表先規(guī)定好,如下
const routes=[
{path:'/login',component:login},/*登錄*/
{path:'/home',component:home},/*首頁(yè)*/
{path:'/monitor',component:monitor},/*實(shí)時(shí)監(jiān)控*/
{path: "/orderQuery", component: orderQuery},/*電子圍欄*/
{path: "/fenceSet", component: fenceSet},/*電子圍欄*/
{path:'/orderCenter',component:orderCenter},/*訂單中心*/
{path:'/carctlExamine',component:carctlExamine},/*車管員審批*/
{path:'/partExamine',component:partExamine},/*部門領(lǐng)導(dǎo)審批*/
{path:'/vpExamine',component:vpExamine},/*副總審批*/
{path:'/distribute',component:distribute},/*調(diào)度派單*/
{path:'/receipt',component:receipt},/*回執(zhí)*/
{path:'/trajectory',component:trajectory},/*軌跡回放*/
{path:'/statistics',component:statistics },/*統(tǒng)計(jì)*/
{path:'/car',component:car},/*車輛管理*/
{path:'/user',component:user},/*用戶管理*/
{path:'/equipment',component:equipment},/*設(shè)備管理*/
{path:'/group',component:group},/*小組維護(hù)*/
{path:'/driver',component:driver},/*駕駛員管理*/
{path: '/company', component: company},/*公司管理*/
{path: '/adminManage', component: adminManage},/*公司員管理*/
{path: '/roleManage', component: roleManage},/*角色管理*/
{path:'/systemDaily',component:systemDaily },/*系統(tǒng)日志*/
];
2.把前端路由表發(fā)給后臺(tái)和后臺(tái)協(xié)商返回的數(shù)據(jù)形式,在app.vue中,使用《el=menu》循環(huán)出來(lái)后臺(tái)返回的路由表如下
<el-menu
:default-active="$route.path"
class="el-menu-demo"
mode="horizontal"
@select="handleSelect"
background-color="#545c64"
text-color="#fff"
active-text-color="#85ffca">
<el-menu-item :index="item.path" v-for="item in pathList"
v-if="item.path!=null" :key="item.id" >
<router-link :to="item.path">{{item.name}}</router-link>
</el-menu-item>/*一級(jí)導(dǎo)航*/
<el-submenu v-if="item.path==null" :key="item.id":index="item.name" v-for="item in pathList">
<template slot="title">{{item.name}}</template>
<el-menu-item v-for="child in item.children" :index="child.path"
:key="child.id" v-if="child.path!=null" >/*二級(jí)導(dǎo)航*/
<router-link :to="child.path">{{child.name}}</router-link>
</el-menu-item>
<el-submenu v-if="child.children!=[]&&child.path==null" v-for="child in item.children":key="child.id":index="child.name" >
<template slot="title">{{child.name}}</template>
<el-menu-item v-for="three in child.children":index="three.path":key="three.id">/*若存在三級(jí)導(dǎo)航*/
<router-link :to="three.path">{{three.name}}</router-link>
</el-menu-item>
</el-submenu>
</el-submenu>
</el-menu>
這樣就可以在登錄的時(shí)候根據(jù)接口獲取到當(dāng)前用戶所擁有的權(quán)限以及路由表,這樣動(dòng)態(tài)路由就做好了 。我們是根據(jù)頁(yè)面來(lái)確定權(quán)限的,沒有頁(yè)面就代表沒有權(quán)限無(wú)法查看頁(yè)面。
以上這篇Vue 配合eiement動(dòng)態(tài)路由,權(quán)限驗(yàn)證的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue實(shí)現(xiàn)密碼顯示與隱藏按鈕的自定義組件功能
本文通過(guò)兩種思路給大家介紹vue實(shí)現(xiàn)密碼顯示與隱藏按鈕的自定義組件功能,感興趣的朋友跟隨小編一起看看吧2019-04-04
vue 實(shí)現(xiàn)通過(guò)手機(jī)發(fā)送短信驗(yàn)證碼注冊(cè)功能
這篇文章主要介紹了vue 實(shí)現(xiàn)通過(guò)手機(jī)發(fā)送短信驗(yàn)證碼注冊(cè)功能的相關(guān)資料,需要的朋友可以參考下2018-04-04
vue項(xiàng)目實(shí)現(xiàn)左滑刪除功能(完整代碼)
最近在開發(fā)移動(dòng)端項(xiàng)目,通過(guò)向左滑動(dòng)出現(xiàn)刪除按鈕,點(diǎn)擊即可刪除,怎么實(shí)現(xiàn)這個(gè)功能呢,接下來(lái)小編給大家?guī)?lái)實(shí)例代碼幫助大家學(xué)習(xí)vue項(xiàng)目實(shí)現(xiàn)左滑刪除功能,感興趣的朋友跟隨小編一起看看吧2021-05-05
vue結(jié)合Echarts實(shí)現(xiàn)點(diǎn)擊高亮效果的示例
下面小編就為大家分享一篇vue結(jié)合Echarts實(shí)現(xiàn)點(diǎn)擊高亮效果的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
Vue實(shí)現(xiàn)開關(guān)按鈕拖拽效果
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)開關(guān)按鈕拖拽效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-09-09

