美文网首页
vue+element实现顶部导航栏+左侧导航栏,选择侧边导航栏

vue+element实现顶部导航栏+左侧导航栏,选择侧边导航栏

作者: Poppy11 | 来源:发表于2020-08-11 14:46 被阅读0次

直接上效果图,顶部导航选择自动化测试,出现左侧导航,左侧导航选择新建任务,这时候自动化测试也处于高亮状态,并且刷新也会仍然选中,并且当我们打开自动化测试时,默认是选中第一个的,这时候我们可以设置默认子路由

image.png

一、 首先配置路由列表

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'login',
      component: login
    },
    {
      path: '/index',
      name: 'index',
      component: index,
      children: [
        {
          path: '/createPackage',
          name: 'createPackage',
          component: createPackage,
          meta: {
            activeMenu: '/createPackage'
          },
        },
        {
          path: '/packageList/:config_id',
          name: 'packageList',
          component: packageList,
          meta: {
            activeMenu: '/packageList/:config_id'
          },
        },
        {
          path: '/tagmanage',
          name: 'tagmanage',
          component: tagmanage,
          meta: {
            activeMenu: '/tagmanage'
          },
        },
        {
          path: '/tools',
          name: 'tools',
          component: tools,
          meta: {
            activeMenu: '/tools'
          },
        },
        {
          path: '/antomated-testing',
          name: 'antomated-testing',
          component: layout,
 redirect:'/antomated-testing/publish-task',
          meta: {
            activeMenu: '/antomated-testing'
          },
          children: [
            {
              path: '/antomated-testing/publish-task',
              name: 'antomated-publish-task',
              component: publishTask,
              meta: {
                activeMenu: '/antomated-testing', // 顶部导航 高亮
                ChildrenActiveMenu: '/antomated-testing/publish-task' // 子导航高亮
              }
            },
            {
              path: '/antomated-testing/task-list',
              name: 'antomated-task-list',
              component: taskList,
              meta: {
                activeMenu: '/antomated-testing', // 顶部导航 高亮
                ChildrenActiveMenu: '/antomated-testing/task-list' // 子导航高亮
              }
            },
          ]
        }
      ]
    },
  ]
})
二、配置顶部导航
 <el-menu
          :default-active="$route.meta.activeMenu"
          class="el-menu-demo"
          mode="horizontal"
          @select="handleSelect"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b">
 <el-menu-item index="/antomated-testing">
         <router-link to="/antomated-testing" style="display:block;height:100%;">自动化测试</router-link>
</el-menu-item>
</el-menu>
三、配置左侧导航栏,这边就是主要用computed检测这个数据,左侧导航栏我使用了递归动态生成导航,不懂得可以看看我另一片文章https://www.jianshu.com/p/6b34abeb6db7
 <el-menu
        router
        :default-active="activeMenu"
        class="el-menu-vertical-demo"
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b">
        <Menu :menuList="LeftMenus"/>
</el-menu>

<script>
  import Menu from './menu'
  import menuList from "../../../config/menuConfig";

  export default {
    components: {Menu},
    name: "Layout",
    data() {
      return {
        LeftMenus: menuList
      }
    },
    computed: {
      activeMenu() {
        const route = this.$route
        console.log(route)
        const { meta, path } = route
        // if set path, the sidebar will highlight the path you set
        if (meta.ChildrenActiveMenu) { // 注意这里很重要
          return meta.ChildrenActiveMenu
        }
        return path
      }
    },
  }
</script>

相关文章

  • vue+element实现顶部导航栏+左侧导航栏,选择侧边导航栏

    直接上效果图,顶部导航选择自动化测试,出现左侧导航,左侧导航选择新建任务,这时候自动化测试也处于高亮状态,并且刷新...

  • Android

    顶部导航栏 仿京东搜索 顶部导航栏 今日头条导航栏 导航栏快速实现 瀑布流 搜索框带历史记录 tablayout ...

  • swift-导航栏

    swift-导航栏直接上代码 导航栏整体背景颜色 导航栏左侧按钮 自定义 导航栏左侧 隐藏 导航栏右侧图片 参考:...

  • vue路由

    区分登录页面(不含有公共的侧边栏和顶部导航),和普通页面(含有公共的侧边栏和顶部导航) router 下的inde...

  • 1、用bootstrap代替iframe

    网上都说用bootstrap代替ifream。需求:把页面划分成top(顶部导航栏),left(左侧导航栏),ce...

  • bootstrap搭建后台管理页面

    管理页面主体包括4部分,顶部导航栏,左侧导航栏,中间正文页和底部的页脚。其中左侧和顶部使用的是bootstrap的...

  • JS实现侧边栏显示隐藏

    网页中侧边栏是一个重要的排版位置,尤其是侧边导航栏用的最多。在一些窄屏的侧边导航栏中,控制侧边导航栏的显示与隐藏可...

  • 移动端导航栏——交互基础篇

    1:导航栏位置 状态栏下面部分就是导航栏 京东导航栏:左侧logo,右侧扫一扫,消息 网易导航:左侧logo,右侧...

  • iOS11人机交互指南 - 栏-01导航栏 Navigatio

    导航栏 导航栏出现在顶部状态栏的下方,并且能够跨越一系列不同层级的屏幕界面存在。当展开一个新的界面时,导航栏的左侧...

  • vue bootstarp 左侧导航栏可收缩,移动端适配成滑入画

    左右布局,支持左侧导航栏固定可收缩,鼠标移动可触发伸展,左侧导航栏手风琴模式,支持移动端适配,小屏左侧导航栏会变成...

网友评论

      本文标题:vue+element实现顶部导航栏+左侧导航栏,选择侧边导航栏

      本文链接:https://www.haomeiwen.com/subject/mixydktx.html