vue中的面包屑導(dǎo)航組件實(shí)例代碼
vue的面包屑導(dǎo)航組件
用來(lái)將其放到navbar中;
Breadcrumb/index.vue
<template>
<el-breadcrumb class="app-breadcrumb" separator="/">
<transition-group>
<el-breadcrumb-item v-for="(item,index) in levelList" :key="item.path" v-if="item.meta.title">
<span v-if='item.redirect==="noredirect"||index==levelList.length-1' class="no-redirect">{{item.meta.title}}</span>
<router-link v-else :to="item.redirect||item.path">{{item.meta.title}}</router-link>
</el-breadcrumb-item>
</transition-group>
</el-breadcrumb>
</template>
<script>
export default {
name: "idnex",
data(){
return {
levelList:null
}
},
created() {
this.getBreadcrumb()
},
watch:{
$route(){
this.getBreadcrumb()
}
},
methods:{
getBreadcrumb(){
let matched=this.$route.matched.filter(item=>item.name)//$route.matched 將會(huì)是一個(gè)包含從上到下的所有對(duì)象 (副本)。
const first=matched[0]
if(first && first.name !=='dashboard'){//$route.name當(dāng)前路由名稱 ;$route.redirectedFrom重定向來(lái)源的路由的名字
matched=[{ path: '/dashboard', meta: { title: 'dashboard' }}].concat(matched)
}
this.levelList=matched
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.app-breadcrumb.el-breadcrumb {
display: inline-block;
font-size: 14px;
line-height: 50px;
margin-left: 10px;
.no-redirect {
color: #97a8be;
cursor: text;
}
}
</style>
ps:下面在看下一段代碼Vue 面包屑導(dǎo)航
樣式采用的是element ui 中的面包屑設(shè)置的,
<template>
<el-breadcrumb>
<el-breadcrumb-item separator = '/' v-for = "(item,index) in breadlist" :key = 'index' :to="{path: item.path}">{{item.meta.CName}}
</el-breadcrumb-item>
</el-breadcrumb>
</template>
js部分
<script>
export default {
data(){
return {
breadlist: ''
}
},
created() {
this.getBread();
},
methods:{
getBread(){
this.breadlist = this.$route.matched;
this.$route.matched.forEach((item,index)=>{
//先判斷父級(jí)路由是否是空字符串或者meta是否為首頁(yè),直接復(fù)寫路徑到根路徑
item.meta.CName === '首頁(yè)' ? item.path = '/' : this.$route.path === item.path;
});
}
},
watch:{
$route(){
this.getBread();
}
}
}
</script>
總結(jié)
以上所述是小編給大家介紹的vue中的面包屑導(dǎo)航組件實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
- vue項(xiàng)目實(shí)現(xiàn)面包屑導(dǎo)航
- vue實(shí)現(xiàn)動(dòng)態(tài)面包屑導(dǎo)航
- Vue2+element-ui實(shí)現(xiàn)面包屑導(dǎo)航
- vue element-ui實(shí)現(xiàn)動(dòng)態(tài)面包屑導(dǎo)航
- Vue 解決多級(jí)動(dòng)態(tài)面包屑導(dǎo)航的問(wèn)題
- vue+elementUI動(dòng)態(tài)生成面包屑導(dǎo)航教程
- Vuex,iView UI面包屑導(dǎo)航使用擴(kuò)展詳解
- vue2.0 elementUI制作面包屑導(dǎo)航欄
- vue 面包屑導(dǎo)航組件封裝
相關(guān)文章
vue-cli 為項(xiàng)目設(shè)置別名的方法
這篇文章主要介紹了vue-cli 為項(xiàng)目設(shè)置別名的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
Vue+ElementUI踩坑之動(dòng)態(tài)顯示/隱藏表格的列el-table-column問(wèn)題
這篇文章主要介紹了Vue+ElementUI踩坑之動(dòng)態(tài)顯示/隱藏表格的列el-table-column問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11
Vue 動(dòng)態(tài)組件與 v-once 指令的實(shí)現(xiàn)
這篇文章主要介紹了Vue 動(dòng)態(tài)組件與 v-once 指令的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-02-02
vue cli實(shí)現(xiàn)項(xiàng)目登陸頁(yè)面流程詳解
CLI是一個(gè)全局安裝的npm包,提供了終端里的vue命令。它可以通過(guò)vue create快速搭建一個(gè)新項(xiàng)目,或者直接通過(guò)vue serve構(gòu)建新想法的原型。你也可以通過(guò)vue ui通過(guò)一套圖形化界面管理你的所有項(xiàng)目2022-10-10
詳解使用vue-admin-template的優(yōu)化歷程
這篇文章主要介紹了詳解使用vue-admin-template的優(yōu)化歷程,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-05-05
ElementUI表單驗(yàn)證validate和validateField的使用及區(qū)別
Element-UI作為前端框架,最常使用到的就是表單驗(yàn)證,下面這篇文章主要給大家介紹了關(guān)于ElementUI表單驗(yàn)證validate和validateField的使用及區(qū)別,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02
element?select必填項(xiàng)驗(yàn)證回顯問(wèn)題的解決
本文主要介紹了element?select必填項(xiàng)驗(yàn)證回顯問(wèn)題的解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04

