02. 使用Vue3集成Element-Plus快速搭建一个管理系统的页面框架

1493 字约 3 分钟读完15959 次阅读更新于 2026/5/3

Elemen-Plus 简介

Element-Plus 是一套前端 UI 框架,非常适合前端基础比较差的同学,可以通过它快速实现精美的页面样式

官网:https://element-plus.org

国内镜像网站(访问速度快):https://cn.element-plus.org/

Vue3 集成 Element-Plus

安装依赖

npm i element-plus -S

node_modules

卸载 element-plus

 npm uninstall element-plus

在 main.js 里面引入

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'

app.use(ElementPlus, {
  locale: zhCn,
})  

测试使用 Element-plus 组件

使用官方的 按钮组件

<el-button>Default</el-button>
<el-button type="primary">青哥哥</el-button>
<el-button type="success">小武哥哥</el-button>
<el-button type="info">Info</el-button>
<el-button type="warning">Warning</el-button>
<el-button type="danger">Danger</el-button>

Home.vue 测试内容

<template>
  <div>
    <el-button>Default</el-button>
    <el-button type="primary">青哥哥</el-button>
    <el-button type="primary">青哥哥</el-button>
    <el-button type="primary">青哥哥</el-button>
    <el-button type="primary">青哥哥</el-button>
    <el-button type="success">小武哥哥</el-button>
    <el-button type="info">Info</el-button>
    <el-button type="info">Info</el-button>
    <el-button type="info">Info</el-button>
    <el-button type="info">Info</el-button>
    <el-button type="warning">Warning</el-button>
    <el-button type="danger">Danger</el-button>


    <div style="padding: 50px">
      <el-icon size="25" color="green"><ChatDotRound /></el-icon>
      <el-button type="primary" icon="Search">按钮</el-button>

      <el-input placeholder="placeholder" :suffix-icon="Calendar" :prefix-icon="Search"></el-input>
      

    </div>
  </div>
</template>

<script setup>
import {Calendar, Search} from "@element-plus/icons-vue";
</script>


全局使用 icon

安装依赖,注册所有图标

npm install @element-plus/icons-vue

在 main.js 里引入

import * as ElementPlusIconsVue from '@element-plus/icons-vue'

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

使用图标:el-icon、el-input、el-button

el-input:当你在输入框组件里面使用图标,你需要单独导入图标

el-icon、el-button:按钮或者图标组件里面,不需要单独导入图标

Element-Plus 主题色设置

安装依赖 sass、unplugin-vue-components、unplugin-auto-import

npm install -D sass unplugin-vue-components unplugin-auto-import

配置 index.scss 放在 src/assets/css 目录下

@forward "element-plus/theme-chalk/src/common/var.scss" with (
  $colors: (
    "primary": ("base": #2c82ff),
    "success": ("base": #31bf00),
    "warning": ("base": #ffad00),
    "danger": ("base": #e52f2f),
    "info": ("base": #8055ff),
  )
);

配置 vite.config.js

import AutoImport from 'unplugin-auto-import/vite' // 自动导入vue中的组件
import Components from 'unplugin-vue-components/vite' //自动导入ui-组件 比如 element-plus等
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' // 对应组件库引入 ,AntDesignVueResolver

plugins: [
  vue(),
 //element-plus按需导入
  AutoImport({
    resolvers: [ElementPlusResolver()],
  }),
  Components({
    resolvers: [
      // 配置elementPlus采用sass样式配置系统
      ElementPlusResolver({importStyle:"sass"})
    ],
  }),
],  
css: {
  preprocessorOptions: {
    scss: {
      additionalData: `@use "@/assets/css/index.scss" as *;`,
    },
  },
},

安装 element 插件

搭建后台基本框架

框架布局分析

配置头部区域

配置导航菜单

菜单主体颜色:#3a456b

高亮颜色:#537bee

点击 menu 里面的某一项 跳转页面怎么做?

高亮显示当前展示的路由

可以通过 router.currentRoute.value.path 获取当前展示的路由

:default-active="router.currentRoute.value.path"

图片取色器

https://www.jyshare.com/front-end/6214/#65ae8f

#e6ecf7

主体区域

配置一个 card 卡片样式

.card {
    background-color: white;
    padding: 10px;
    border-radius: 5px;
    box-shadow: 0 0 8px rgba(0, 0, 0, .12);
}

本节课笔记内容

Manager.vue

Home.vue

global.css

:root {
    --el-color-primary: green;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    color: #333;
    font-size: 14px;
}

a {
    text-decoration: none;
}

.card {
    background-color: white;
    padding: 10px;
    border-radius: 5px;
    box-shadow: 0 0 8px rgba(0, 0, 0, .12);
}