<template>
  <el-breadcrumb class="breadcrumb" :separator-icon="ArrowRight">
    <transition-group name="breadcrumb">
      <el-breadcrumb-item v-for="(item, index) in breadcrumbData" :key="index + 'id'">
        <span v-if="index === breadcrumbData.length - 1" class="no-redirect" style="color:black">{{ item.meta.title
          }}</span>
        <span v-else class="no-redirect">{{ item.meta.title }}</span>
      </el-breadcrumb-item>
    </transition-group>
  </el-breadcrumb>
</template>

<script setup>
  import { ref, watch } from "vue";
  import { useRoute, useRouter } from "vue-router";
  import { ArrowRight } from '@element-plus/icons-vue'

  const route = useRoute();
  const router = useRouter();

  // 生成数组数据
  const breadcrumbData = ref([]);
  const getBreadcrumbData = () => {
    breadcrumbData.value = route.matched.filter((item) => {
      console.log(item)
      return item.meta && item.meta.title;
    });
  };
  const goTo = (path)=> {
    router.push(path)
  }
  // 监听路由发生改变时触发
  watch(
    route,
    () => {
      getBreadcrumbData();
    },
    {
      immediate: true,
    }
  );



</script>
<style lang="css" scoped>
  .breadcrumb-enter-active,
  .breadcrumb-leave-active {
    transition: all 0.5s;
  }
  .breadcrumb-enter-from,
  .breadcrumb-leave-active {
    opacity: 0;
    transform: translateX(20px);
  }

  .breadcrumb-leave-active {
    position: absolute;
  }

  .breadcrumb{
    margin-bottom: 20px;
  }
</style>