Breadcrumbs.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <ol>
  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. import * as _ from "lodash";
  24. export default defineComponent({
  25. setup() {
  26. const {route, $config, app: {i18n}} = useContext()
  27. const $router = useRouter()
  28. const homeUrl = $config.baseURL_adminLegacy
  29. const crumbs = computed(()=>{
  30. const fullPath = route.value.path
  31. const params = fullPath.startsWith('/') ? fullPath.substring(1).split('/') : fullPath.split('/')
  32. const crumbs:Array<AnyJson> = []
  33. let path = ''
  34. params.forEach((param, index) => {
  35. path = `${path}/${param}`
  36. const match = $router.match(path)
  37. if (match.name !== null) {
  38. const title = !parseInt(param, 10) ? i18n.t(param.replace(/-/g, ' ') + '_breadcrumbs') : i18n.t('item')
  39. crumbs.push({
  40. title: title,
  41. ...match,
  42. })
  43. }
  44. })
  45. return crumbs
  46. })
  47. return {
  48. crumbs,
  49. homeUrl
  50. }
  51. }
  52. })
  53. </script>
  54. <style scoped>
  55. ol {
  56. list-style: none;
  57. padding-left: 12px;
  58. padding-top: 10px;
  59. }
  60. li {
  61. display: inline;
  62. }
  63. li:after {
  64. content: ' / ';
  65. display: inline;
  66. font-size: 12px;
  67. color: grey ;
  68. padding: 0 0.0725em 0 0.15em;
  69. }
  70. li:last-child:after {
  71. content: '';
  72. }
  73. li a.nuxt-link-exact-active.nuxt-link-active > span {
  74. color: grey !important;
  75. }
  76. li a > span{
  77. font-size: 12px;
  78. }
  79. </style>