首页 > 其他 > 详细

面包屑导航 $route.matched

时间:2020-06-02 14:37:34      阅读:139      评论:0      收藏:0      [点我收藏+]

基本适用于所有面面包屑导航

技术分享图片

 

 技术分享图片

 

技术分享图片

 

 

 


<template>
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ name: ‘Index‘ }">首页</el-breadcrumb-item>
    <el-breadcrumb-item v-for="(item, index) in breadList" :key="index">{{item}}</el-breadcrumb-item>
  </el-breadcrumb>
</template>
<script>
export default {
  // 初始化数据对象
  data() {
    return {
      breadList: []
    };
  },
  // 监听属性
  watch: {
    // 监听路由
    $route(val) {
      console.log(val,‘valvalvalvalvalvalval‘)
      // 调用获取路由数组方法
      this.getBreadList(val);
    }
  },
  // 自定义事件
  methods: {
    /**
     * @description 获取路由数组
     * @params val 路由参数
     * @author tw
     */
    getBreadList(val) {
      this.breadList = [];
      // 过滤路由matched对象
      if (val.matched) {
        let matched = val.matched.filter(item => item.meta && item.meta.title);
        console.log(matched,‘面包屑导航‘)
        // 拿到过滤好的路由v-for遍历出来
        //this.breadList = matched;
        for (var i = 0; i < matched.length; i++) {
          if (matched[i].meta.parentTitle) {
            this.breadList.push(matched[i].meta.parentTitle);
          }
          this.breadList.push(matched[i].meta.title);
        }
      }
    }
  }
  
};
</script>
<style lang="scss" scoped>
/* 面包屑导航 */
.el-breadcrumb {
  margin-top: 20px;
  font-size: 14px;
}
</style>

面包屑导航 $route.matched

原文:https://www.cnblogs.com/maibao666/p/13030956.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!