element 面包屑

本文详细介绍了如何在Vue项目中实现面包屑导航功能,通过监听路由变化更新面包屑列表,展示了具体的代码实现和路由守卫的使用。

面包屑。vue

 

<template>

<p class="level-bread">

<el-breadcrumb separator="/">

<el-breadcrumb-item v-for="item in realList" :to="item.path" :key="item.name">{{item.title}}</el-breadcrumb-item>

</el-breadcrumb>

<!-- <router-view /> -->

</p>

</template>

 

<script>

export default {

name: "lelve-bread",

created(){

this.getRoutePath();

},

data() {

return {

realList: []

}

},

methods:{

getRoutePath() {

this.realList = this.$route.meta.routeList;

}

},

beforeRouteEnter(to,from, next) {

next((vm) => {

vm.realList = to.meta.routeList;

});

},

// watch:{

// $route:function(newV,oldV) {

// this.realList =newV.meta.routeList;

// }

// }

}

</script>
 
main.js
 
var routeList = [];

router.beforeEach((to, from, next) => {
console.log(from)
console.log(to)
var index = -1;

for(var i = 0; i < routeList.length; i++) {

if(routeList[i].name == to.name) {

index = i;

break;

}

}

if (index !== -1) {

//如果存在路由列表,则把之后的路由都删掉

routeList.splice(index + 1, routeList.length - index - 1);

} else if(to.name != '登录'){

routeList.push({"name":to.name,"path":to.fullPath, 'title': to.params.hhh});

}

to.meta.routeList = routeList;

next()

});
 

转载于:https://www.cnblogs.com/cs122/p/10478886.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值