兩層for循環(huán)渲染側(cè)邊欄數(shù)據(jù)

<template>

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

? ? <el-header>

? ? ? <div><img style="width: 50px;height: 50px;" src="../assets/logo.png" alt=""><span>后臺(tái)管理系統(tǒng)</span></div>

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

? ? </el-header>

? ? <el-container>

? ? ? <!-- 側(cè)邊欄菜單區(qū) -->

? ? ? <el-aside width="200px">

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

? ? ? ? ? <!-- 一級(jí) -->

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

? ? ? ? ? ? <!-- 1級(jí)菜單模板區(qū) -->

? ? ? ? ? ? <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>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容