Vue使用element-ui/plus组件布局容器container失效解决方法
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
免费下载资源
·
这个错我遇到了好几次,每一次都花了很长时间解决,还是决定写个笔记记录一下。
在使用elementu官网的布局容器时,他是这样的。
<el-container>
<el-header>Header</el-header>
<el-main>Main</el-main>
</el-container>
<el-container>
<el-header>Header</el-header>
<el-main>Main</el-main>
<el-footer>Footer</el-footer>
</el-container>
<el-container>
<el-aside width="200px">Aside</el-aside>
<el-main>Main</el-main>
</el-container>
<el-container>
<el-header>Header</el-header>
<el-container>
<el-aside width="200px">Aside</el-aside>
<el-main>Main</el-main>
</el-container>
</el-container>
<el-container>
<el-header>Header</el-header>
<el-container>
<el-aside width="200px">Aside</el-aside>
<el-container>
<el-main>Main</el-main>
<el-footer>Footer</el-footer>
</el-container>
</el-container>
</el-container>
<el-container>
<el-aside width="200px">Aside</el-aside>
<el-container>
<el-header>Header</el-header>
<el-main>Main</el-main>
</el-container>
</el-container>
<el-container>
<el-aside width="200px">Aside</el-aside>
<el-container>
<el-header>Header</el-header>
<el-main>Main</el-main>
<el-footer>Footer</el-footer>
</el-container>
</el-container>
<style>
.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>
我在确定elementui引入正确的情况下是这样写的。
<template>
<el-container>
<SideNav></SideNav>
<el-container>
<el-main><Main></Main></el-main>
<el-footer><Footer></Footer></el-footer>
</el-container>
</el-container>
</template>
<script>
import SideNav from "@/components/SideNav";
import HomeHeader from "@/pages/Home/HomeHeader";
import "element-ui/lib/theme-chalk/index.css";
import Header from "@/components/Header";
export default {
name: "Home",
components: { SideNav, HomeHeader, Header },
};
</script>
<style scoped>
.baseContainer {
height: 100%;
width: 100%;
position: relative;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;
}
.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>
注意,我在SideNav,Header,Main,Footer组件套了el-aside,el-header...然后暴露出来在Home中引用。
当然错误,布局一片混乱。想了一下午终于懂了。
原来,elementui不支持这种写法,在Home里面应该完全遵循官网的写法,el-aside,el-header,el-mian,el-footer等必须写在container的同一个组件,不能写在子组件里面然后引入,不然elementui不会识别为布局容器。
正确写法
<template>
<el-container>
<el-aside>
<SideNav></SideNav>
</el-aside>
<el-container>
<el-main><Main></Main></el-main>
<el-footer><Footer></Footer></el-footer>
</el-container>
</el-container>
</template>
<script>
import SideNav from "@/components/SideNav";
import HomeHeader from "@/pages/Home/HomeHeader";
import "element-ui/lib/theme-chalk/index.css";
import Header from "@/components/Header";
export default {
name: "Home",
components: { SideNav, HomeHeader, Header },
};
</script>
<style scoped>
.baseContainer {
height: 100%;
width: 100%;
position: relative;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;
}
.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>
言语稚嫩,希望对你有帮助!
GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45
7 个月前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 7 个月前
更多推荐
已为社区贡献2条内容
所有评论(0)