Breadcrumb.vue 1.39 KB
<!--
 * @Description: 
 * @Autor: renchao
 * @LastEditTime: 2023-03-20 16:36:51
-->
<template>
  <el-breadcrumb class="breadcrumb" separator-class="el-icon-arrow-right">
    <span class="fl">当前页面:</span>
    <transition-group name="breadcrumb">
      <el-breadcrumb-item v-for="(item, index) in levelList" :key="item.path">
        <span @click.prevent="handleLink(item)">{{ item.meta.title }}</span>
      </el-breadcrumb-item>
    </transition-group>
  </el-breadcrumb>
</template>

<script>
import pathToRegexp from "path-to-regexp";

export default {
  data () {
    return {
      levelList: null,
    };
  },
  watch: {
    $route () {
      this.getBreadcrumb();
    },
  },
  created () {
    this.getBreadcrumb();
  },
  methods: {
    getBreadcrumb () {
      // only show routes with meta.title
      this.levelList = this.$route.matched.filter(
        (item) => item.meta && item.meta.title
      )
      if (this.$route.matched[0].path == '/jsbwcx') {
        this.levelList = this.levelList.slice(-1)
      }
    },
    isDashboard (route) {
      const name = route && route.name;
      if (!name) {
        return false;
      }
      return (
        name.trim().toLocaleLowerCase() === "Dashboard".toLocaleLowerCase()
      );
    },
    pathCompile (path) {
      const { params } = this.$route;
      var toPath = pathToRegexp.compile(path);
      return toPath(params);
    }
  }
}
</script>