68 lines
1.6 KiB
Vue
68 lines
1.6 KiB
Vue
<template>
|
|
<el-breadcrumb class="breadcrumb-wrap" separator="/">
|
|
<transition-group name="breadcrumb">
|
|
<el-breadcrumb-item v-for="(item, index) in breadcrumData" :key="item.path">
|
|
<!---不可点击-->
|
|
<span class="no-redirect" v-if="index === breadcrumData.length - 1">{{ item.meta.title }}</span>
|
|
<!---可点击项-->
|
|
<span class="redirect" v-else @click="onLinkClick(item)">{{ item.meta.title }}</span>
|
|
</el-breadcrumb-item>
|
|
</transition-group>
|
|
</el-breadcrumb>
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
import { useStore } from 'vuex'
|
|
import { watch, ref } from 'vue';
|
|
import { useRoute, useRouter } from 'vue-router';
|
|
const route = useRoute();
|
|
|
|
//生成数组数据
|
|
const breadcrumData = ref([]);
|
|
const getBreadcrumData = () => {
|
|
//当前路由的标准化路由纪录
|
|
breadcrumData.value = route.matched.filter(item => item.meta && item.meta.title)
|
|
}
|
|
|
|
//watch监听路由变化
|
|
watch(route, () => {
|
|
getBreadcrumData();
|
|
}, {
|
|
immediate: true
|
|
})
|
|
|
|
const store = useStore();
|
|
const linkHoverColor = ref(store.getters.cssVar.menuBg);
|
|
|
|
const router = useRouter();
|
|
const onLinkClick = (item) => {
|
|
router.push(item.path)
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.breadcrumb-wrap {
|
|
display: inline-block;
|
|
font-size: 14px;
|
|
line-height: 50px;
|
|
margin-left: 8px;
|
|
|
|
.no-redirect {
|
|
color: #97a8be;
|
|
cursor: text;
|
|
}
|
|
|
|
.redirect {
|
|
color: #666;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.redirect:hover {
|
|
// 将来需要进行主题替换,所以这里不去写死样式
|
|
color: v-bind(linkHoverColor);
|
|
}
|
|
}
|
|
</style>
|