请求得到侧边列表后v-for循环

本文介绍了一种基于Element UI的后台管理系统布局方案,包括头部、主体和侧边栏的设计。主要内容涵盖使用Vue.js实现的动态菜单加载及权限控制,通过菜单项ID动态分配图标,以及退出登录功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template>
  <el-container class="haaa">
    <!-- 头部 -->
    <el-header>
      <div><span></span><span>后台管理系统</span></div>
      <el-button type="info" @click="logout" :loading="loading">退出</el-button>
    </el-header>
    <!-- 主体 -->
    <el-container>
      <!-- 侧边 -->
      <el-aside width="200px">
        <!-- 侧边菜单栏 -->
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409eff"
        >
          <!-- 一级菜单  -->
          <el-submenu
            :index="item.id + ''"
            v-for="item in menulist"
            :key="item.id"
          >
            <template slot="title">
              <i :class="iconsObj[item.id]"></i>
              <span>{{ item.authName }}</span>
            </template>

            <!-- 二级菜单 -->
            <el-menu-item
              :index="subItem.id + ''"
              v-for="subItem in item.children"
              :key="subItem.id"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ subItem.authName }}</span>
              </template></el-menu-item
            >
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <!-- 左边主体 -->
        <el-main>Main</el-main>
      </el-container>
    </el-container>
  </el-container>
</template>

<script>
export default {
  components: {},
  created() {
    this.getMenuList();
  },
  data() {
    return {
      loading: false,
      menulist: [],
      iconsObj: {
        125: "iconfont icon-user",
        103: "iconfont icon-tijikongjian",
        101: "iconfont icon-shangpin",
        102: "iconfont icon-danju",
        145: "iconfont icon-baobiao",
      },
    };
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.loading = true;
      setTimeout(() => {
        //需要延迟的代码 :3秒后延迟跳转到首页,可以加提示什么的
        this.$router.push("/Login").catch(() => {
          //此处可以添加一个弹窗,例如:
        });
        //延迟时间:2秒
      }, 2000);
    },
    // 获取所有的菜单
    async getMenuList() {
      // 接口请求地址menus
      const { data: res } = await this.$http.get("menus");
      console.log(res);
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.menulist = res.data;
    },
  },
};
</script>
<style lang="less" scoped>
.haaa {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  color: #ffffff;
  font-size: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-left: 0;
  div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}
.el-aside {
  background-color: #333744;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #eaedf1;
  color: #333;
  text-align: center;
  line-height: 160px;
}
/deep/.el-submenu__title {
  padding-left: 0px !important;
  padding-right: 60px !important;
}
/deep/.el-menu-item {
  padding-left: 60px !important;
  padding-right: 40px !important;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

呱嗨喵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值