前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >vue2实现后台管理系统的侧边栏切换子页面

vue2实现后台管理系统的侧边栏切换子页面

原创
作者头像
肥晨
修改2023-05-16 15:33:50
修改2023-05-16 15:33:50
6910
举报
文章被收录于专栏:农民工前端农民工前端

导文

vue2实现后台管理系统的侧边栏切换子页面

文章重点

路由写法

代码语言:shell
复制
const router = new Router({
    routes: [{
            path: '/',
            redirect: "Home"
        },
        {
            path: '/Home',
            component: Home,
            redirect: '/deviceList',//第一次出现展示的子页面
            children: [{//子页面
                    path: '/deviceList',
                    component: deviceList,
                },
            ]
        },
        {
            path: '/login',
            component: login
        },

    ]
})

侧边栏

elementui代码
代码语言:shell
复制
 <el-menu
      :default-active="activeIndex"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      background-color="#338acf"
      text-color="#fff"
      active-text-color="#fff"
      unique-opened
      router
    >
      <el-submenu :index="item.id + ''" v-for="item in menulist" :key="item.id">
        <template slot="title">
          <iconSvg :iconname="item.iconName" class="headerIcon" />
          <span>{{ item.autName }}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item
            :index="'/' + subItem.path"
            v-for="subItem in item.children"
            :key="subItem.id"
            :disabled="subItem.disableds"
          >
            <div
              :style="{
                backgroundColor:
                  '/' + subItem.path == activeIndex
                    ? 'rgba(7, 167, 235, 1)'
                    : '',
              }"
              class="submenuItem"
            >
              <iconSvg :iconname="subItem.iconName" class="headerIcon" />
              <span>{{ subItem.autName }}</span>
            </div>
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
data值
代码语言:shell
复制
   menulist: [
        {
          id: 1,
          autName: "设备管理",
          iconName: "icon-shebeiguanli",
          children: [
            {
              id: "1 - 1",
              autName: "设备列表",
              iconName: "icon-liebiao",
              path: "deviceList",
            },
          ],
        },
   
        },
       
监听页面当前路由值
代码语言:shell
复制
      this.activeIndex = this.$route.path; // 通过他就可以监听到当前路由状态并激活当前菜单

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 导文
  • 文章重点
    • 路由写法
    • 侧边栏
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档