Breadcrumb.vue 1000 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <script setup lang="ts">
  2. import {computed, ref} from 'vue'
  3. import {useRoute} from 'vue-router'
  4. interface bread {
  5. name: any
  6. path: string
  7. }
  8. const name = ref()
  9. const route = useRoute()
  10. const breadList = computed(() => {
  11. let _breadList: bread[] = []
  12. name.value = route.name
  13. route.matched.forEach(item => {
  14. //item.name !== 'index' && this.breadList.push(item)
  15. _breadList.push({
  16. name: item.name,
  17. path: item.path
  18. })
  19. })
  20. return _breadList
  21. })
  22. </script>
  23. <template>
  24. <a-breadcrumb class="breadcrumb">
  25. <a-breadcrumb-item v-for="(item, index) in breadList" :key="item.name">
  26. <router-link
  27. v-if="item.name !== name && index !== 1"
  28. :to="{ path: item.path === '' ? '/' : item.path }"
  29. >{{ item.name() }}
  30. </router-link>
  31. <span v-else>{{ item.name() }}</span>
  32. </a-breadcrumb-item>
  33. </a-breadcrumb>
  34. </template>
  35. <style scoped>
  36. </style>