天天看点

若依前后端分离默认跳转到第一个子菜单

// 菜单选择事件
handleSelect(key, keyPath) {
  this.currentIndex = key;
  if (this.ishttp(key)) {
  // http(s):// 路径新窗口打开
  window.open(key, "_blank");
  } else if (key.indexOf("/redirect") !== -1) {
  // /redirect 路径内部打开
  this.$router.push({ path: key.replace("/redirect", "") });
  } else {
  // 显示左侧联动菜单
  this.activeRoutes(key);

  let myRoutes = [];
  if (this.childrenMenus && this.childrenMenus.length > 0) {
    this.childrenMenus.map((item) => {
    if (key == item.parentPath || (key == "index" && "" == item.path)) {
      myRoutes.push(item);
    }
    });
  }
  setTimeout(() => {
    if(myRoutes[0].path != this.$route.path) {
    this.$router.replace({
      path: myRoutes[0].path
    })
    } else {
    this.$router.replace({
      path: '/index'
    })
    }
  }, 100)
  }
},      

继续阅读