vue tab栏 动态路由得添加

思路

一:通过接口获取路由配置(这个就不叙述了 不同得公司返回得东西都不太一样)

主要有以下几项
1.tabName 名字
2.path 链接
3.对应要加载组件得名称(根据这个去决定加载什么组件)
4是否是第一级得路由 这么一个字段

二,添加

添加一级路由
// 1级路由
      let obj={
          path: "/login2",
          component:resolve =>require(['../page/login'],resolve),
          name:"登录2",
          meta: { title: "登录2"},
        }
        this.$router.options.routes.push(obj)
        //重新挂载路由
this.$router.addRoutes(this.$router.options.routes)

添加二级路由
// 二级路由
      let obj1={
          path: "login2",
          component:resolve =>require(['../page/login'],resolve),
          name:"登录2",
          meta: { title: "登录2"},
        }
       for(let i in  this.$router.options.routes){
        if(this.$router.options.routes[i].name=='登录'){		//这个是判断放在哪个路由得二级下面
          if(this.$router.options.routes[i].children){

          }else{
            this.$router.options.routes[i].children=[]
            
          }
          this.$router.options.routes[i].children.push(obj1)
        }
      }
          //重新挂载路由
this.$router.addRoutes(this.$router.options.routes)

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值