【Vue.js + Element UI】实现左侧导航栏制作

在这里插入图片描述

利用Element UI进行页面搭建

/components/Menu.vue

<template>
  <div class="aside">
    <!-- 导航菜单组件
      el-menu: 容器组件
      @open 监听下拉打开
      @close 监听下拉菜单打开
      default-active string 默认选中的菜单项的index的值
      text-color: 文本的颜色
      active-text-color: 菜单被选中时的文本颜色
      router: 是否使用vue-router的模式进行跳转,启用该模式激活导航时以Index作为
      参数进行路由跳转
      default-active 设置为当前路由的path
     -->
    <el-menu
      router
      :default-active="$route.path"
      class="el-menu-vertical-demo"
      background-color="#3d5f81"
      text-color="#fff"
      active-text-color="#ffd04b"
    >
      <!-- 没有下级菜单的菜单项 -->
      <el-menu-item index="/statistics">
        <i class="el-icon-menu"></i>
        <span slot="title">首页</span>
      </el-menu-item>
      <!-- 有下级菜单的菜单项 -->
      <el-submenu index="1">
        <template slot="title">
          <i class="el-icon-s-tools"></i>
          <span>系统管理</span>
        </template>
        <!-- 一组菜单项 -->
        <el-menu-item-group>
          <el-menu-item index="/menu">菜单管理</el-menu-item>
          <el-menu-item index="/role">角色管理</el-menu-item>
          <el-menu-item index="/admin">管理员管理</el-menu-item>
        </el-menu-item-group>
      </el-submenu>

       <el-submenu index="2">
        <template slot="title">
          <i class="el-icon-s-goods"></i>
          <span>商城管理</span>
        </template>
        <!-- 一组菜单项 -->
        <el-menu-item-group>
          <el-menu-item index="/category">商品分类</el-menu-item>
          <el-menu-item index="/specs">商品规格</el-menu-item>
          <el-menu-item index="/goods">商品管理</el-menu-item>
          <el-menu-item index="/seckill">秒杀活动</el-menu-item>
          <el-menu-item index="/banner">轮播图管理</el-menu-item>
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
export default {}
</script>

<style scoped>
.aside {
  background: #3d5f81;
  height: 100%;
}
.el-menu {
  border-right: none;
}
</style>

配置路由

/src/router/routes.js

const routes = [
  {
    path: '/',
    // 重定向
    redirect: '/statistics',
    name: 'Index',
    component: () => import('@/pages/main/Index'),
    children: [
      {
        path: 'statistics',
        name: 'statistics',
        component: () => import('@/pages/statistics/Index'),
        meta: {
          title: '图表统计'
        }
      },
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/pages/menu/Index'),
        meta: {
          title: '菜单管理'
        }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/pages/role/Index'),
        meta: {
          title: '角色管理'
        }
      },
      {
        path: 'admin',
        name: 'admin',
        component: () => import('@/pages/admin/Index'),
        meta: {
          title: '管理员管理'
        }
      },
      {
        path: 'category',
        name: 'category',
        component: () => import('@/pages/category/Index'),
        meta: {
          title: '商品分类'
        }
      },
      {
        path: 'specs',
        name: 'specs',
        component: () => import('@/pages/specs/Index'),
        meta: {
          title: '商品规格'
        }
      },
      {
        path: 'goods',
        name: 'goods',
        component: () => import('@/pages/goods/Index'),
        meta: {
          title: '商品管理'
        }
      },
      {
        path: 'seckill',
        name: 'seckill',
        component: () => import('@/pages/seckill/Index'),
        meta: {
          title: '秒杀活动'
        }
      },
      {
        path: 'banner',
        name: 'banner',
        component: () => import('@/pages/banner/Index'),
        meta: {
          title: '轮播图'
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/pages/login/Index'),
    meta: {
      title: '登录'
    }
  }
]

export default routes

GitHub 加速计划 / eleme / element
14
2
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:2 个月前 )
c345bb45 1 年前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 1 年前
Logo

新一代开源开发者平台 GitCode,通过集成代码托管服务、代码仓库以及可信赖的开源组件库,让开发者可以在云端进行代码托管和开发。旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐