<template>
<el-container>
<el-aside width="200px">
<el-col :span="24">
<el-menu
default-active="2" unique-opened
class="el-menu-vertical-demo">
<el-submenu :index="item.id + '' " v-for="item in menulist" :key="item.id">
<template slot="title">
<i class="el-icon-location"></i>
<span>{{item.authName}}</span>
</template>
<el-menu-item-group v-for="subitem in item.children" :key="subitem.id">
<el-menu-item :index="subitem.id + '' ">{{subitem.authName}}</el-menu-item>
</el-menu-item-group>
</el-submenu>
</el-menu>
</el-col>
</el-aside>
<el-container>
<el-header>
<div>电商后台</div>
<el-button type="primary" @click="logout">退出</el-button>
</el-header>
<el-main>Main</el-main>
<el-footer>Footer</el-footer>
</el-container>
</el-container>
</template>
<script>
export default {
data(){
return{
menulist:[]
}
},
created() {
this.getMenuList()
},
methods: {
logout () {
window.sessionStorage.clear()
this.$router.push('/login')
},
async getMenuList(){ //解构data
const { data: res } = await this.$http.get('menus')
if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
this.menulist = res.data
console.log(res)
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.el-container{height: 100%}
.el-header{display: flex;justify-content: space-between;align-items:center}
.el-header, .el-footer {
background-color: #B3C0D1;
color: #333;
text-align: center;
line-height: 60px;
}
.el-aside {
background-color: #D3DCE6;
color: #333;
text-align: center;
line-height: 200px;
}
.el-main {
background-color: #E9EEF3;
color: #333;
text-align: center;
line-height: 160px;
}
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>