<template>
<div>
<el-breadcrumb
separator-class="el-icon-arrow-right"
style="padding-left: 30px"
>
<el-breadcrumb-item
v-for="(item, index) in breadList"
:key="index"
:to="item.path"
>{{ item.meta.title }}</el-breadcrumb-item
>
</el-breadcrumb>
</div>
</template>
<script>
export default {
watch: {
$route() {
this.getBreadcrumb();
},
},
created() {
this.getBreadcrumb();
},
data() {
return {
breadList: [],
};
},
methods: {
isHome(route) {
return route.name === "main";
},
getBreadcrumb() {
let matched = this.$route.matched;
if (!this.isHome(matched[0])) {
matched = [{ path: "/main", meta: { title: "首页" } }].concat(matched);
}
this.breadList = matched;
},
},
};
</script>
<style>
</style>
路由配置:
const routes = [{
path: '',
redirect: '/login',
},
......
......
......
{
name: 'main',
path: '/main',
component: () => import('@/pages/main/mainPage'),
meta: {
title: "首页"
},
......
......
......
}
]