# 认识 Element
# 一、介绍
Element Plus
,一套为开发者、设计师和产品经理准备的基于 Vue 3.0
的桌面端组件库。- 由饿了么团队出品,提供了配套
axure
、sektch
设计资源,可以直接下载使用,能帮我等搬砖人员节省大量的时间。 - 使用现成的
UI
组件库,能快速搭建项目,后期也容易维护,在敏捷开发项目中尤为常见。设计师可以下载设计文件,在做设计图时直接使用模板,既能快速出图,也保证了前端还原实现。 - 官网:https://element-plus.org/zh-CN/open in new window
# 二、安装
npm install element-plus --save
yarn add element-plus
# 三、引入Element Plus
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
const app = createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component);
}
app.use(store).use(router).use(ElementPlus, { size: "small", zIndex: 3000 }).mount("#app");
# 四、Basic
基础组件
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|
size | 尺寸 | string | large、middle、small | - |
type | 类型 | string | primary、success、warning、danger、info、text | - |
plain | 是否为朴素按钮 | boolean | - | false |
text | 是否为文字按钮 | boolean | - | false |
bg | 是否显示文字按钮背景颜色 | boolean | - | false |
link | 是否为链接按钮 | boolean | - | false |
round | 是否为圆角按钮 | boolean | - | false |
circle | 是否为圆形按钮 | boolean | - | false |
loading | 是否为加载中状态 | boolean | - | false |
disabled | 按钮是否为禁用状态 | boolean | - | false |
<template>
<div>
<el-button>默认</el-button>
<el-button size="large">大</el-button>
<el-button size="middle">中</el-button>
<el-button size="small">小</el-button>
<el-button>默认</el-button>
<el-button type="primary">主要</el-button>
<el-button type="success">成功</el-button>
<el-button type="info">信息</el-button>
<el-button type="warning">警告</el-button>
<el-button type="danger">危险</el-button>
<el-button type="text">文本</el-button>
<el-button type="success">成功</el-button>
<el-button type="success" plain>朴素按钮</el-button>
<el-button type="success" text>文字按钮</el-button>
<el-button type="success" bg>显示文字按钮背景颜色</el-button>
<el-button type="success" text bg>组合使用</el-button>
<el-button type="success" link>链接按钮</el-button>
<el-button type="success" round>圆角按钮</el-button>
<el-button type="success" circle>圆形按钮</el-button>
<el-button type="success" loading>加载中状态</el-button>
<el-button type="success" disabled>禁用状态</el-button>
</div>
</template>
<el-button-group></el-button-group>
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|
size | 用于控制该按钮组内按钮的大小 | string | large、middle、small | - |
type | 用于控制该按钮组内按钮的类型 | string | primary、success、warning、danger、info、text | - |
<template>
<div>
<el-button-group>
<el-button>添加</el-button>
<el-button>修改</el-button>
<el-button>删除</el-button>
</el-button-group>
<el-button-group size="large">
<el-button>添加</el-button>
<el-button>修改</el-button>
<el-button>删除</el-button>
</el-button-group>
<el-button-group size="middle">
<el-button>添加</el-button>
<el-button>修改</el-button>
<el-button>删除</el-button>
</el-button-group>
<el-button-group size="small">
<el-button>添加</el-button>
<el-button>修改</el-button>
<el-button>删除</el-button>
</el-button-group>
<el-button-group type="primary">
<el-button>添加</el-button>
<el-button>修改</el-button>
<el-button>删除</el-button>
</el-button-group>
<el-button-group type="success">
<el-button>添加</el-button>
<el-button>修改</el-button>
<el-button>删除</el-button>
</el-button-group>
</div>
</template>
# 3、Icon
图标
参数 | 描述 | 类型 | 可选值 | 默认值 |
---|
color | 颜色 | Pick <CSSProperties, 'color'> | - | inherit |
size | 大小 | number | string | - |
npm install @element-plus/icons-vue
yarn add @element-plus/icons-vue
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
}
app.use(store).use(router).use(ElementPlus).mount('#app')
<template>
<div>
<el-icon><AddLocation /></el-icon>
<el-icon color="red"><AddLocation /></el-icon>
<el-icon size="48px"><AddLocation /></el-icon>
<el-button-group type="success">
<el-button><el-icon><AddLocation /></el-icon>添加</el-button>
<el-button><el-icon><Edit /></el-icon>修改</el-button>
<el-button><el-icon><DeleteFilled /></el-icon>删除</el-button>
</el-button-group>
</div>
</template>
# 4、布局
参数 | 描述 | 类型 | 可选值 | 默认值 |
---|
gutter | 栅格间隔 | number | - | 0 |
justify | flex 布局下的水平排列方式 | string | start、end、center、space-around、space-between、space-evenly | start |
align | flex 布局下的垂直排列方式 | string | top、middle、bottom | top |
tag | 自定义元素标签 | string | - | div |
参数 | 描述 | 类型 | 可选值 | 默认值 |
---|
xs | < 768px 响应式栅格数或者栅格属性对象 | number/object (例如 {span: 4, offset: 4}) | - | - |
sm | ≥ 768px 响应式栅格数或者栅格属性对象 | number/object (例如 {span: 4, offset: 4}) | - | - |
md | ≥ 992px 响应式栅格数或者栅格属性对象 | number/object (例如 {span: 4, offset: 4}) | - | - |
lg | ≥ 1200px 响应式栅格数或者栅格属性对象 | number/object (例如 {span: 4, offset: 4}) | - | - |
xl | ≥ 1920px 响应式栅格数或者栅格属性对象 | number/object (例如 {span: 4, offset: 4}) | - | - |
span | 栅格占据的列数 | number | - | 24 |
offset | 栅格左侧的间隔格数 | number | - | 0 |
push | 栅格向右移动格数 | number | - | 0 |
pull | 栅格向左移动格数 | number | - | 0 |
tag | 自定义元素标签 | string | * | div |
<template>
<div>
<el-row>
<el-col :xs="6">欧阳克</el-col>
<el-col :xs="6">朱天蓬</el-col>
<el-col :xs="6">灭绝师太</el-col>
<el-col :xs="6">西门大官人</el-col>
</el-row>
<el-row>
<el-col :xs="8">欧阳克</el-col>
<el-col :xs="8">朱天蓬</el-col>
<el-col :xs="8">灭绝师太</el-col>
<el-col :xs="8">西门大官人</el-col>
</el-row>
<el-row>
<el-col :xl="8">欧阳克</el-col>
<el-col :xl="8">朱天蓬</el-col>
<el-col :xl="8">灭绝师太</el-col>
<el-col :xl="8">西门大官人</el-col>
</el-row>
<el-row>
<el-col :xl="8" :xs="6">欧阳克</el-col>
<el-col :xl="8" :xs="6">朱天蓬</el-col>
<el-col :xl="8" :xs="6">灭绝师太</el-col>
<el-col :xl="8" :xs="6">西门大官人</el-col>
</el-row>
<el-row gutter="100">
<el-col :xl="8" :xs="6">欧阳克</el-col>
<el-col :xl="8" :xs="6">朱天蓬</el-col>
<el-col :xl="8" :xs="6">灭绝师太</el-col>
<el-col :xl="8" :xs="6">西门大官人</el-col>
</el-row>
<el-row>
<el-col :xl="8" :xs="6" :offset="6">欧阳克</el-col>
<el-col :xl="8" :xs="6">朱天蓬</el-col>
<el-col :xl="8" :xs="6">灭绝师太</el-col>
<el-col :xl="8" :xs="6">西门大官人</el-col>
</el-row>
<el-row>
<el-col :xl="8" :xs