vue+element中如何加入外部链接

配置路由

{
     
        path: '/jobs-admin',
        component: LeftNav,
        name: '任务调度', // 当前路由的name
        leaf: true, // 只有一个节点
        iconCls: 'el-icon-s-help', // 图标样式class
        menuShow: true,
         external:true,//说明是外部链接
        children: [
          {
      path: '/jobs-admin', component: RightC, name: '任务调度', menuShow: true }
        ]
      },

然后再home.vue中

fetchNavData () {
      // 初始化菜单激活项
        var cur_path = this.$route.path; //获取当前路由
        var routers = this.$router.options.routes; // 获取路由对象
      
        console.log(cur_path,routers);
        var nav_type = "", nav_name = "";
        for (var i = 0; i < routers.length; i++) {
     
          var children = routers[i].children;
          
          if(children){
     
            for (var j = 0; j < children.length; j++) {
     
            	
              var grand_children = children[j].children;
              if(grand_children){
     
                for (var k = 0; k < grand_children.length; k++) {
     
                  if (grand_children[k].path === cur_path) {
     
                    nav_type = routers[i].type;
                    nav_name = routers[i].name;
                    break;
                  }
                  // 如果该菜单下还有子菜单
                  if(grand_children[k].children) {
     
                        let grandChildren = grand_children[k].children;
                        for(let z=0; z<grandChildren.length; z++) {
     
                          if(grandChildren[z].path === cur_path) {
     
                            nav_type = routers[i].type;
                            nav_name = routers[i].name;
                            break;
                          }
                        }
                  }

                }
              }
            }
          }
        }
        this.$store.state.topNavstore.topNavState = nav_type;  // 改变topNavState状态的值
        this.$store.state.topNavstore.leftNavState = nav_name;  // 改变leftNavState状态的值
        
        if(nav_name == "enterprise"){
     
          this.defaultActiveIndex = "/";
          
        } else {
     
          this.defaultActiveIndex = "/" + nav_name + "Manager";
          
        }
     //   console.log(nav_name,nav_type,this.defaultActiveIndex);
    
    //这里把外部链接配置为动态的
	if(this.$route.external){
     //说明是外部链接
		for(var a= 0 ; a<this.resourcesList.length; a++){
     
  			if(this.resourcesList[a].sysKey == "technologyManager" && this.$route.path == this.resourcesList[a].resCode){
     
  				window.open(this.resourcesList[a].resAction, '_blank').location;
      		return ;
  			}

  		}
	}
   

注意,新开页面打开外部链接,window.open(this.resourcesList[a].resAction, ‘_blank’).location;

你可能感兴趣的:(vue)