Blame view

src/components/Breadcrumb.vue 1.39 KB
任超 committed
1 2 3 4 5
<!--
 * @Description: 
 * @Autor: renchao
 * @LastEditTime: 2023-03-20 16:36:51
-->
yangwei committed
6
<template>
任超 committed
7 8 9 10 11 12 13 14
  <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>
yangwei committed
15 16 17 18 19 20
</template>

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

export default {
21
  data () {
yangwei committed
22 23 24 25 26
    return {
      levelList: null,
    };
  },
  watch: {
27
    $route () {
yangwei committed
28 29 30
      this.getBreadcrumb();
    },
  },
31
  created () {
yangwei committed
32 33 34
    this.getBreadcrumb();
  },
  methods: {
35
    getBreadcrumb () {
yangwei committed
36
      // only show routes with meta.title
37
      this.levelList = this.$route.matched.filter(
yangwei committed
38
        (item) => item.meta && item.meta.title
任超 committed
39 40 41 42
      )
      if (this.$route.matched[0].path == '/jsbwcx') {
        this.levelList = this.levelList.slice(-1)
      }
yangwei committed
43
    },
44
    isDashboard (route) {
yangwei committed
45 46 47 48 49 50 51 52
      const name = route && route.name;
      if (!name) {
        return false;
      }
      return (
        name.trim().toLocaleLowerCase() === "Dashboard".toLocaleLowerCase()
      );
    },
53
    pathCompile (path) {
yangwei committed
54 55 56
      const { params } = this.$route;
      var toPath = pathToRegexp.compile(path);
      return toPath(params);
57 58 59
    }
  }
}
任超 committed
60
</script>