uni-breadcrumb-item.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <view class="uni-breadcrumb-item">
  3. <view :class="{
  4. 'uni-breadcrumb-item--slot': true,
  5. 'uni-breadcrumb-item--slot-link': to && currentPage !== to.path
  6. }" @click="navTo">
  7. <slot />
  8. </view>
  9. <i v-if="separatorClass" class="uni-breadcrumb-item--separator" :class="separatorClass" />
  10. <text v-else class="uni-breadcrumb-item--separator">{{ separator }}</text>
  11. </view>
  12. </template>
  13. <script>
  14. /**
  15. * BreadcrumbItem 面包屑导航子组件
  16. * @property {String/Object} to 路由跳转页面路径/对象
  17. * @property {Boolean} replace 在使用 to 进行路由跳转时,启用 replace 将不会向 history 添加新记录(仅 h5 支持)
  18. */
  19. export default {
  20. data() {
  21. return {
  22. currentPage: ''
  23. }
  24. },
  25. props: {
  26. to: {
  27. type: [String, Object],
  28. default: ''
  29. }
  30. },
  31. inject: ['uniBreadcrumb'],
  32. computed: {
  33. separator() {
  34. return this.uniBreadcrumb.separator
  35. },
  36. separatorClass() {
  37. return this.uniBreadcrumb.separatorClass
  38. }
  39. },
  40. watch: {
  41. $route: {
  42. immediate: true,
  43. handler(val) {
  44. this.currentPage = val.path
  45. }
  46. }
  47. },
  48. methods: {
  49. navTo() {
  50. const {
  51. to,
  52. $router
  53. } = this
  54. if (this.currentPage === to.path) return
  55. if (to && $router) {
  56. this.replace ?
  57. $router.replace(to) :
  58. $router.push(to)
  59. }
  60. }
  61. }
  62. }
  63. </script>
  64. <style lang="scss">
  65. $uni-primary: #2979ff !default;
  66. $uni-base-color: #6a6a6a !default;
  67. $uni-main-color: #3a3a3a !default;
  68. .uni-breadcrumb-item {
  69. display: flex;
  70. align-items: center;
  71. white-space: nowrap;
  72. font-size: 14px;
  73. &--slot {
  74. color: $uni-base-color;
  75. padding: 0 10px;
  76. &-link {
  77. color: $uni-main-color;
  78. font-weight: bold;
  79. /* #ifndef APP-NVUE */
  80. cursor: pointer;
  81. /* #endif */
  82. &:hover {
  83. color: $uni-primary;
  84. }
  85. }
  86. }
  87. &--separator {
  88. font-size: 12px;
  89. color: $uni-base-color;
  90. }
  91. &:last-child &--separator {
  92. display: none;
  93. }
  94. &:first-child &--slot {
  95. padding-left: 0;
  96. }
  97. }
  98. </style>