halo/src/components/Tools/Breadcrumb.vue

46 lines
979 B
Vue
Raw Normal View History

2019-03-20 12:22:52 +00:00
<template>
<a-breadcrumb class="breadcrumb">
<a-breadcrumb-item
v-for="(item, index) in breadList"
:key="item.name"
>
2019-04-10 12:29:41 +00:00
<router-link
v-if="item.name != name && index != 1"
:to="{ path: item.path === '' ? '/' : item.path }"
>{{ item.meta.title }}</router-link>
2019-03-20 12:22:52 +00:00
<span v-else>{{ item.meta.title }}</span>
</a-breadcrumb-item>
</a-breadcrumb>
</template>
<script>
export default {
2019-03-22 02:14:41 +00:00
data() {
2019-03-20 12:22:52 +00:00
return {
name: '',
breadList: []
}
},
2019-03-22 02:14:41 +00:00
created() {
2019-03-20 12:22:52 +00:00
this.getBreadcrumb()
},
methods: {
2019-03-22 02:14:41 +00:00
getBreadcrumb() {
2019-03-20 12:22:52 +00:00
this.breadList = []
2019-04-10 12:29:41 +00:00
// this.breadList.push({name: 'index', path: '/dashboard/', meta: {title: '首页'}})
2019-03-20 12:22:52 +00:00
this.name = this.$route.name
this.$route.matched.forEach((item) => {
2019-04-10 12:29:41 +00:00
// item.name !== 'index' && this.breadList.push(item)
2019-03-20 12:22:52 +00:00
this.breadList.push(item)
})
}
},
watch: {
2019-03-22 02:14:41 +00:00
$route() {
2019-03-20 12:22:52 +00:00
this.getBreadcrumb()
}
}
}
</script>