index.vue
1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<template>
<el-breadcrumb class="app-breadcrumb" separator="/">
<transition-group name="breadcrumb">
<el-breadcrumb-item
v-for="(item, index) in levelListArr"
:key="item.path"
>
<span
v-if="
item.redirect === 'noredirect' || index == levelListArr.length - 1
"
class="no-redirect"
>{{ item.meta.title }}</span
>
<router-link
v-else
:to="item.redirect || item.path"
class="no-redirect"
>{{ item.meta.title }}</router-link
>
</el-breadcrumb-item>
</transition-group>
</el-breadcrumb>
</template>
<script>
import pathToRegexp from "path-to-regexp";
export default {
data() {
return {
levelList: null
};
},
watch: {
$route() {
this.getBreadcrumb();
}
},
computed: {
levelListArr() {
return this.levelList.filter(item => item.meta && item.meta.title);
}
},
created() {
this.getBreadcrumb();
},
methods: {
getBreadcrumb() {
const { params } = this.$route;
let matched = this.$route.matched.filter(item => {
if (item.name) {
// To solve this problem https://github.com/PanJiaChen/vue-element-admin/issues/561
let toPath = pathToRegexp.compile(item.path);
item.path = toPath(params);
return true;
}
});
// const first = matched[0]
// if (first && first.name !== 'dashboard') {
// 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;
color: #fff;
.no-redirect {
color: #333;
cursor: text;
}
}
</style>