詳解基于iview-ui的導(dǎo)航欄路徑(面包屑)配置
起因
上家公司的后臺(tái)管理系統(tǒng)都是刷表刷出來(lái)的,所用很久很久沒(méi)寫(xiě)后臺(tái)管理系統(tǒng)了。換了工作后總算要開(kāi)始搗騰router了,很久沒(méi)用都快忘光了,所以把一些通用的模塊記錄一下,也分享給需要的朋友們。
經(jīng)過(guò)
//router.js
let routes = [
{
path: '/',
redirect: '/admin',
},
{
path: '/login',
name: 'login',
meta: {title: '登錄'},
component: () => import('./components/login.vue')
},
{
path: '/admin',
name: 'admin',
meta: {title: '主頁(yè)'},
component: () => import('./components/admin.vue'),
children: [
{
path: 'operation',
name: 'operation',
meta: {title: '運(yùn)營(yíng)管理'},
component: () => import('./components/admin/operation.vue')
},
{
path: 'order',
name: 'order',
meta: {title: '訂單中心'},
redirect: 'order/index',
component: () => import('./components/admin/order.vue'),
children: [
{
path: 'index',
name: 'index',
meta: {title: ''},
component: () => import('./components/admin/ordercenter.vue')
},
{
path: 'detail',
name: 'detail',
meta: {title: '訂單詳情'},
component: () => import('./components/admin/orderdetail.vue')
},
]
},
]
},
]
export default routes
這個(gè)是我部分的router路徑配置表
/*面包屑路徑處理*/
eve_breadcrumbItem_change(){
var list = this.$route.fullPath.split('/')//list[0]:是空格
this.BreadcrumbItem = []
function fn(obj, arr, index,self) {
if (obj.hasOwnProperty('children')&&obj['children'].length>0) {
for (let one of obj.children) {
if (one.name != 'index' && one.name == arr[index]) {
self.BreadcrumbItem.push({'title': one.meta.title, 'path': list.slice(0,index+1).join('/')})
return one.hasOwnProperty('children')&&one['children'].length>0?fn(one,arr,index+1,self):false
}
}
}
}
for(let one of this.$router.options.routes){
if(one.hasOwnProperty('name')&&one.name == list[1]){
this.BreadcrumbItem.push({'title': one.meta.title, 'path': one.path})
fn(one,list,2,this)
}
}
}
這個(gè)是就是本文的重點(diǎn),其實(shí)也簡(jiǎn)單,就是遞歸了下路徑名重新組裝了下數(shù)據(jù)給面包屑傳過(guò)去
watch: {
'$route'(to, from) {
this.eve_breadcrumbItem_change()
}
},
...
mounted() {
this.eve_breadcrumbItem_change()
},
使用也簡(jiǎn)單,無(wú)非watch檢測(cè)下路徑變化,避免刷新頁(yè)面時(shí)沒(méi)路徑,在mounted里再調(diào)用一下。
結(jié)果
結(jié)果嘛,自然就解決問(wèn)題。不過(guò)路徑的配置可能會(huì)和大家的不同,我喜歡在分組下默認(rèn)弄個(gè)index路徑,我覺(jué)得這樣結(jié)構(gòu)比較好,這里大家注意下。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳解Vue-axios 設(shè)置請(qǐng)求頭問(wèn)題
這篇文章主要介紹了Vue-axios 設(shè)置請(qǐng)求頭問(wèn)題,文中給大家提到了axios設(shè)置請(qǐng)求頭內(nèi)容的方法,需要的朋友可以參考下2018-12-12
vue實(shí)現(xiàn)頁(yè)面打印自動(dòng)分頁(yè)的兩種方法
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)頁(yè)面打印自動(dòng)分頁(yè)的兩種方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09
Vue中關(guān)于this指向的問(wèn)題示例詳解
在Vue中,方法體里用this調(diào)用vue實(shí)例的數(shù)據(jù),有時(shí)會(huì)指向window,導(dǎo)致調(diào)用失敗報(bào)錯(cuò),這篇文章主要介紹了Vue中關(guān)于this指向的問(wèn)題 ,需要的朋友可以參考下2022-07-07
elementPuls 表格反選實(shí)現(xiàn)示例代碼
這篇文章主要介紹了elementPuls 表格反選實(shí)現(xiàn)示例代碼,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-07-07
Vue中安裝element-ui失敗問(wèn)題原因及解決
Vue中安裝element-ui失敗問(wèn)題原因及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01
elementui如何解決el-table重復(fù)寫(xiě)loading問(wèn)題
這篇文章主要介紹了elementui如何解決el-table重復(fù)寫(xiě)loading問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08
vue實(shí)現(xiàn)web前端登錄頁(yè)數(shù)字驗(yàn)證碼
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)web前端登錄頁(yè)數(shù)字驗(yàn)證碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06
vue項(xiàng)目中使用ts(typescript)入門(mén)教程
最近項(xiàng)目需要將原vue項(xiàng)目結(jié)合ts的使用進(jìn)行改造,本文從安裝到vue組件編寫(xiě)進(jìn)行了說(shuō)明,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11
如何優(yōu)雅的在一臺(tái)vps(云主機(jī))上面部署vue+mongodb+express項(xiàng)目
這篇文章主要介紹了如何優(yōu)雅的在一臺(tái)vps(云主機(jī))上面部署vue+mongodb+express項(xiàng)目,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-01-01

