Element UI 是一款基于 Vue 2.x 的桌面端组件库,由饿了么前端团队开辟保护。它供给了一系列高品质组件,帮助开辟者构建美不雅、易用且功能丰富的页面。跟着 Vue 3 的发布,Element UI 也推出了其 Vue 3 版本——Element Plus。本文将深刻剖析 Element UI 跟 Element Plus,帮助开辟者高效上手,打造专业界面计划。
Element UI 是一款基于 Vue.js 的桌面端组件库,供给了一套完全的企业级组件,包含表格、表单、弹窗等。它广泛利用于企业级项目,存在精良的牢固性跟坚固性,同时拥有富强的社区支撑跟丰富的文档资本。
在开端利用 Element UI 之前,须要先安装 Element UI,并在项目中引入相干的款式跟组件。
npm install element-ui --save
在 main.js
中引入 Element UI 并注册组件:
import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
按钮是网页中罕见的交互元素,Element UI 供给了多种款式的按钮供开辟者抉择。
<template>
<div>
<el-button>默许按钮</el-button>
<el-button type="primary">重要按钮</el-button>
<el-button type="success">成功按钮</el-button>
<el-button type="warning">警告按钮</el-button>
<el-button type="danger">伤害按钮</el-button>
</div>
</template>
表单是收集用户输入信息的重要组件。
<template>
<el-form :model="form" ref="form">
<el-form-item label="用户名" prop="username">
<el-input v-model="form.username"></el-input>
</el-form-item>
<el-form-item label="密码" prop="password">
<el-input type="password" v-model="form.password"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm">提交</el-button>
</el-form-item>
</el-form>
</template>
<script>
export default {
data() {
return {
form: {
username: '',
password: ''
}
};
},
methods: {
submitForm() {
this.$refs.form.validate((valid) => {
if (valid) {
alert('submit!');
} else {
console.log('error submit!!');
return false;
}
});
}
}
};
</script>
Element Plus 是基于 Vue 3 跟 TypeScript 的 UI 组件库,是 Element UI 的进级版本。它供给了丰富的组件跟功能,并且拥有完全的中文文档。
Element Plus 在保持原有功能的基本上,针对现代 Web 开辟停止了优化。它存在以下特点:
npm install element-plus --save
在 main.js
中引入 Element Plus 并注册组件:
import { createApp } from 'vue';
import App from './App.vue';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
const app = createApp(App);
app.use(ElementPlus);
app.mount('#app');
Element UI 跟 Element Plus 是两款优良的 Vue 组件库,它们可能帮助开辟者疾速构建专业界面计划。经由过程本文的剖析,信赖开辟者曾经对这两个组件库有了更深刻的懂得,可能更好地利用于现实项目中。