vue3引入elementplus后使用布局容器不生效

问题说明

vue集成了elementplus

main.js

import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

var app = createApp(App)
app.use(router)
app.use(ElementPlus)

app.mount('#app')

使用了elementplus布局组件

<template>
  <el-container>
    <el-header>Headerel-header>
    <el-container>
      <el-aside width="200px">Asideel-aside>
      <el-main>Mainel-main>
    el-container>
  el-container>
template>

页面展示效果如下:
vue3引入elementplus后使用布局容器不生效_第1张图片

问题解决方法一:
在布局所在的文件中加入css

<template>
  <el-container>
    <el-header>Headerel-header>
    <el-container>
      <el-aside width="200px">Asideel-aside>
      <el-main>Mainel-main>
    el-container>
  el-container>
template>

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

问题解决方法二:
在style.css中加入布局容器的css,在main.js中引入style.css

style.css


  .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;
  }

main.js

import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

var app = createApp(App)
app.use(router)
app.use(ElementPlus)

app.mount('#app')

问题解决
vue3引入elementplus后使用布局容器不生效_第2张图片

你可能感兴趣的:(vue,elementuiplus,vue.js,css,前端)