• 面包屑导航 $route.matched


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

     


    <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>
  • 相关阅读:
    C#后台正则表达式
    Layer 弹出层抖动问题
    JS中子页面父页面方法 变量相互调用
    layer最大话.最小化.还原回调方法
    trove远程连接mongodb
    tar.gz tar.bz2的解压命令
    IO测试工具之fio详解
    HTTP请求方法
    jmeter --使用put方法上传文件
    DHCP的原理和实现过程
  • 原文地址:https://www.cnblogs.com/maibao666/p/13030956.html
Copyright © 2020-2023  润新知