1.首页布局
<template>
<!-- 头部区域 -->
<el-container class="body_container">
<el-header>Header<el-button type="info" @click="loginOut">退出</el-button></el-header>
<!-- 页面主体区域 -->
<el-container>
<!-- 侧边栏 -->
<el-aside width="200px">Aside</el-aside>
<!-- 右侧主体区域 -->
<el-main>Main</el-main>
</el-container>
</el-container>
</template>
.el-header{
background-color: #373d41;
}
.el-aside{
background-color:#333744;
}
.el-main{
background-color: #eaedf1;
}
.body_container{
height: 100%;
}
2.头部布局
<el-header>
<div>
<img src="../../assets/images/logo-header.png" alt="" class="logo_image">
<span>电商后台管理系统</span>
</div>
<el-button type="info" @click="loginOut">退出</el-button>
</el-header>
.el-header{
background-color: #373d41;
display: flex;
justify-content: space-between;
padding-left:0;
align-items: center;
color: #fff;
font-size: 20px;
>div{
display: flex;
align-items: center;
span{
margin-left: 15px;
}
}
}
.el-aside{
background-color:#333744;
}
.el-main{
background-color: #eaedf1;
}
.body_container{
height: 100%;
}
.logo_image{
height: 80px;
width: 80px;
background-color: #333744;
}
3.获取数据
通过axios请求拦截器添加token,保证用户有获取数据的权限
在main.js中
axios.interceptors.request.use(config => {
config.headers.Authorization = window.sessionStorage.getItem("token") //设置响应头
return config
}, err => {
console.log(err)
})
在首页组件中
data() {
return {
menuList: []
};
},
created() {
this.getMenList();
},
async getMenList() {
const { data: res } = await this.$http.get("menus");
if (res.meta.status !== 200) {
return this.$message.error(res.meta.msg);
}
this.menuList = res.data;
}