jinjianback1.1/src/components/Breadcrumb/index.vue

52 lines
1.3 KiB
Vue
Raw Normal View History

2017-06-26 13:38:24 +08:00
<template>
2017-11-24 14:01:54 +08:00
<el-breadcrumb class="app-breadcrumb" separator="/">
2017-11-24 16:30:40 +08:00
<transition-group name="breadcrumb">
2017-11-24 17:21:32 +08:00
<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>
2017-11-24 16:30:40 +08:00
<router-link v-else :to="item.redirect||item.path">{{item.meta.title}}</router-link>
</el-breadcrumb-item>
</transition-group>
2017-06-26 13:38:24 +08:00
</el-breadcrumb>
</template>
<script>
2017-08-30 17:42:06 +08:00
export default {
created() {
this.getBreadcrumb()
},
data() {
return {
levelList: null
}
},
2017-11-24 17:21:32 +08:00
watch: {
$route() {
this.getBreadcrumb()
}
},
2017-08-30 17:42:06 +08:00
methods: {
getBreadcrumb() {
let matched = this.$route.matched.filter(item => item.name)
const first = matched[0]
2017-11-24 16:30:40 +08:00
if (first && first.name !== 'dashboard') {
2017-11-24 17:08:30 +08:00
matched = [{ path: '/dashboard', meta: { title: 'Dashboard' }}].concat(matched)
2017-06-26 13:38:24 +08:00
}
2017-08-30 17:42:06 +08:00
this.levelList = matched
}
}
}
2017-06-26 13:38:24 +08:00
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
2017-11-24 16:30:40 +08:00
.app-breadcrumb.el-breadcrumb {
display: inline-block;
font-size: 14px;
line-height: 50px;
margin-left: 10px;
.no-redirect {
color: #97a8be;
cursor: text;
}
2017-08-30 17:42:06 +08:00
}
2017-06-26 13:38:24 +08:00
</style>