Breadcrumbs.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <ol id="breadcrumbs">
  3. <li>
  4. <a class="no-decoration" :href="homeUrl + '/'">
  5. <span class="ot_green--text">{{$t('welcome')}}</span>
  6. </a>
  7. </li>
  8. <li
  9. v-for="(crumb, index) in crumbs"
  10. :key="index"
  11. >
  12. <NuxtLink class="no-decoration" :to="crumb.path">
  13. <span class="ot_green--text">{{
  14. crumb.title
  15. }}</span>
  16. </NuxtLink>
  17. </li>
  18. </ol>
  19. </template>
  20. <script lang="ts">
  21. import {defineComponent, computed, useContext, useRouter} from '@nuxtjs/composition-api'
  22. import {AnyJson} from "~/types/interfaces";
  23. export default defineComponent({
  24. setup() {
  25. const {route, $config, app: {i18n}} = useContext()
  26. const $router = useRouter()
  27. const homeUrl = $config.baseURL_adminLegacy
  28. const crumbs = computed(()=>{
  29. const fullPath = route.value.path
  30. const params = fullPath.startsWith('/') ? fullPath.substring(1).split('/') : fullPath.split('/')
  31. const crumbs:Array<AnyJson> = []
  32. let path = ''
  33. params.forEach((param, index) => {
  34. path = `${path}/${param}`
  35. const match = $router.match(path)
  36. if (match.name !== null) {
  37. const title = !parseInt(param, 10) ? i18n.t(param + '_breadcrumbs') : i18n.t('item')
  38. crumbs.push({
  39. title: title,
  40. ...match,
  41. })
  42. }
  43. })
  44. return crumbs
  45. })
  46. return {
  47. crumbs,
  48. homeUrl
  49. }
  50. }
  51. })
  52. </script>
  53. <style scoped>
  54. ol {
  55. list-style: none;
  56. padding-left: 12px;
  57. padding-top: 10px;
  58. }
  59. li {
  60. display: inline;
  61. }
  62. li:after {
  63. content: ' / ';
  64. display: inline;
  65. font-size: 12px;
  66. color: grey ;
  67. padding: 0 0.0725em 0 0.15em;
  68. }
  69. li:last-child:after {
  70. content: '';
  71. }
  72. li a.nuxt-link-exact-active.nuxt-link-active > span {
  73. color: grey !important;
  74. }
  75. li a > span{
  76. font-size: 12px;
  77. }
  78. </style>