vBread.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <!--
  2. * @Author : yuanrunwei
  3. * @Date : 2020-05-18 12:05:37
  4. * @LastEditors: XuTongZhang
  5. * @LastEditTime: 2020-07-28 16:40:45
  6. * @FilePath : \ambre-admin-noob\src\components\vBread\vBread.vue
  7. -->
  8. <template>
  9. <div class="vBreadCom">
  10. <el-breadcrumb v-if="$route.name === 'home'" separator="/">
  11. <el-breadcrumb-item class="home">首页</el-breadcrumb-item>
  12. <el-breadcrumb-item class="select">首页</el-breadcrumb-item>
  13. </el-breadcrumb>
  14. <el-breadcrumb v-else separator="/">
  15. <el-breadcrumb-item class="home">{{first}}</el-breadcrumb-item>
  16. <el-breadcrumb-item class="select">{{last}}</el-breadcrumb-item>
  17. </el-breadcrumb>
  18. </div>
  19. </template>
  20. <script>
  21. export default {
  22. props: {
  23. path: {
  24. type: String,
  25. default: () => '0-0'
  26. },
  27. nav: {
  28. type: Array,
  29. default: () => []
  30. }
  31. },
  32. data () {
  33. return {
  34. first: '',
  35. last: ''
  36. }
  37. },
  38. watch: {
  39. $route () {
  40. this.getBreadcrumb()
  41. }
  42. },
  43. methods: {
  44. getBreadcrumb () {
  45. let parentName = []
  46. this.nav.forEach(item => {
  47. parentName.push({
  48. name: item.name,
  49. child: item.child
  50. })
  51. })
  52. parentName.forEach(item => {
  53. item.child.forEach(i => {
  54. if (i.to === this.$route.name) {
  55. this.first = item.name
  56. this.last = i.name
  57. }
  58. })
  59. })
  60. }
  61. }
  62. }
  63. </script>
  64. <style lang='scss'>
  65. @import './vBread.scss';
  66. </style>