element-plus布局容器不生效

390 阅读1分钟

引言

element-plus提供了很多优秀的布局容器。 比如上下,左右。 但在项目中直接引入常常会不生效。作者实现效果JeecgFlow

实际代码

<template>
  <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>
</template>

实际并没有按照文档的显示的效果。

解决之道

  • 在main.ts中
import { createApp } from 'vue'
//去掉这段引入,也可以保留这个style.css 将布局容器样式加入
// import './style.css'
import App from './App.vue'
  • 在所需的页面中添加样式
<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>

  • 顶部空隙
//布局容器代码的引入常会出现顶部未贴合。 解决办法是找到index.html,追加样式值。
<body style="margin: 0;">
    <div id="app"></div>
    <script type="module" src="/src/main.ts"></script>
 </body>

  • 最终效果页面

WX20231029-212618@2x.png