Rap 原分销系统代码Web
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0ac6fd093464aa5ad0cc81b4ad69f8590b5855f9.svn-base 2.1KB

5 maanden geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <el-breadcrumb class="app-breadcrumb" separator="/">
  3. <transition-group name="breadcrumb">
  4. <el-breadcrumb-item v-for="(item,index) in levelList" :key="item.path">
  5. <span v-if="item.redirect==='noredirect'||index==levelList.length-1" class="no-redirect">{{ item.meta.title }}</span>
  6. <a v-else @click.prevent="handleLink(item)">{{ item.meta.title }}</a>
  7. </el-breadcrumb-item>
  8. </transition-group>
  9. </el-breadcrumb>
  10. </template>
  11. <script>
  12. import pathToRegexp from 'path-to-regexp'
  13. export default {
  14. data() {
  15. return {
  16. levelList: null
  17. }
  18. },
  19. watch: {
  20. $route(route) {
  21. // if you go to the redirect page, do not update the breadcrumbs
  22. if (route.path.startsWith('/redirect/')) {
  23. return
  24. }
  25. this.getBreadcrumb()
  26. }
  27. },
  28. created() {
  29. this.getBreadcrumb()
  30. },
  31. methods: {
  32. getBreadcrumb() {
  33. // only show routes with meta.title
  34. let matched = this.$route.matched.filter(item => item.meta && item.meta.title)
  35. const first = matched[0]
  36. if (!this.isDashboard(first)) {
  37. matched = [{ path: '/dashboard', meta: { title: '首页' }}].concat(matched)
  38. }
  39. this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
  40. },
  41. isDashboard(route) {
  42. const name = route && route.name
  43. if (!name) {
  44. return false
  45. }
  46. return name.trim().toLocaleLowerCase() === 'Dashboard'.toLocaleLowerCase()
  47. },
  48. pathCompile(path) {
  49. // To solve this problem https://github.com/PanJiaChen/vue-element-admin/issues/561
  50. const { params } = this.$route
  51. var toPath = pathToRegexp.compile(path)
  52. return toPath(params)
  53. },
  54. handleLink(item) {
  55. const { redirect, path } = item
  56. if (redirect) {
  57. this.$router.push(redirect)
  58. return
  59. }
  60. this.$router.push(this.pathCompile(path))
  61. }
  62. }
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. .app-breadcrumb.el-breadcrumb {
  67. display: inline-block;
  68. font-size: 14px;
  69. line-height: 50px;
  70. margin-left: 8px;
  71. .no-redirect {
  72. color: #97a8be;
  73. cursor: text;
  74. }
  75. }
  76. </style>