这个错我遇到了好几次,每一次都花了很长时间解决,还是决定写个笔记记录一下。
在使用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不会识别为布局容器。
正确写法文章来源:https://www.toymoban.com/news/detail-507872.html
<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>
言语稚嫩,希望对你有帮助!文章来源地址https://www.toymoban.com/news/detail-507872.html
到了这里,关于Vue使用element-ui/plus组件布局容器container失效解决方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!