两层for循环渲染侧边栏数据

<template>

  <el-container class="home-container">

    <el-header>

      <div><img style="width: 50px;height: 50px;" src="../assets/logo.png" alt=""><span>后台管理系统</span></div>

      <el-button type="info" @click="clear">退出</el-button>

    </el-header>

    <el-container>

      <!-- 侧边栏菜单区 -->

      <el-aside width="200px">

        <el-menu background-color="#323744" text-color="#fff" active-text-color="#ffd04b">

          <!-- 一级 -->

          <el-submenu :index="item.id +''" v-for="item in menulist" :key="item.id">

            <!-- 1级菜单模板区 -->

            <template slot="title">

              <i class="el-icon-location"></i>

              <span>{{item.authName}}</span>

            </template>

            <el-menu-item v-for="subitem in item.children" :key="subitem.id" :index="subitem.id+''"><template slot="title">

                <i class="el-icon-location"></i>

                <span>{{subitem.authName}}</span>

              </template></el-menu-item>

          </el-submenu>

        </el-menu>

      </el-aside>

      <el-main>Main</el-main>

    </el-container>

  </el-container>

</template>

<script>

  export default {

    data() {

      return {

        menulist: []

      }

    },

    created() {

      this.getMenu()

    },

    methods: {

      async getMenu() {

        const {

          data: res

        } = await this.$http.get('menus')

        if (res.meta.status !== 200) return this.$msg.error(res.meta.msg)

        this.menulist = res.data

      },

      clear() {

        window.sessionStorage.clear()

        this.$router.push('/login')

      }

    }

  }

</script>

<style lang='less' scoped>

  .el-header {

    background-color: #363B40;

    display: flex;

    justify-content: space-between;

    padding-left: 0px;

    align-items: center;

    color: #FFFFFF;

    font-size: 20px;

    >div {

      display: flex;

      align-items: center;

      span {

        margin-left: 15px;

      }

    }

  }

  .home-container {

    height: 100%;

  }

  .el-aside {

    background-color: #323744;

  }

  .el-main {

    background-color: #EAEDF2;

  }

</style>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容