ElementUI是一个基于Vue.js 2.0的桌面端组件库,它提供了一套丰富的UI组件,包括表格、表单、弹框、按钮、菜单等常用组件,具备易用、美观、高效、灵活等优势,能够极大的提高Web应用的开发效率。ElementUI的文档非常详细,示例丰富,易于入手,同时也支持自定义主题,开发者可以根据自己的需要进行调整。ElementUI同时也支持按需加载,可以减少项目体积,提高网页加载速度。由于其易用性和高效性,ElementUI已成为Vue.js开发的首选UI组件库之一。
安装ElementUI必须借助于vue-cli工具如果没有可观看我上一篇博客
构建好项目后通过npm安装element-ui
cd 项目根路径 #进入新建项目的根目录
npm install element-ui -S #安装element-ui模块

下载好了后进入项目查看package.json查看是否成功(因为有一次某人下载好了cmd窗口并没有提示下载成功)

打开 src目录下的main.js,该文件是项目的入口文件,所以在这里导入,其他组件均可使用,不用再导入。
- import Vue from 'vue'
-
- //新添加1
- import ElementUI from 'element-ui'
- //新增加2,避免后期打包样式不同,要放在import App from './App';之前
- import 'element-ui/lib/theme-chalk/index.css'
-
- import App from './App'
- import router from './router'
-
- Vue.use(ElementUI) //新添加3
- Vue.config.productionTip = false
在目录下新建了一个views专门存放一些界面组件,界面可自己设计,列如:
登录界面:
-
- <template>
- <div class="login-wrap">
- <el-form class="login-container">
- <h1 class="title">用户登录h1>
- <el-form-item label="">
- <el-input type="text" v-model="username" placeholder="登录账号" autocomplete="off">el-input>
- el-form-item>
- <el-form-item label="">
- <el-input type="password" v-model="password" placeholder="登录密码" autocomplete="off">el-input>
- el-form-item>
- <el-form-item>
- <el-button type="warning" style="width:100%;" @click="doSubmit()">提交el-button>
- el-form-item>
- <el-row style="text-align: center;margin-top:-10px">
- <el-link type="primary">忘记密码el-link>
- <el-link type="primary" @click="gotoRegister()">用户注册el-link>
- el-row>
- el-form>
- div>
- template>
-
- <script>
- export default {
- name: 'Login',
- data() {
- return {
- username: '',
- password: ''
- }
- },
- methods: {
- gotoRegister() {
- this.$router.push("/Register");
- }
- }
- }
- script>
-
- <style scoped>
- .login-wrap {
- box-sizing: border-box;
- width: 100%;
- height: 100%;
- padding-top: 10%;
-
- /* background-color: #3b7cf5; */
- background-repeat: no-repeat;
- background-position: center right;
- background-size: 100%;
- }
-
- .login-container {
- border-radius: 10px;
- margin: 0px auto;
- width: 350px;
- padding: 30px 35px 15px 35px;
- border: 1px solid #eaeaea;
- text-align: left;
- background-color: rgba(229, 229, 229, 0.8);
- }
-
- .title {
- margin: 0px auto 40px auto;
- text-align: center;
- color: #0b0b0b;
- }
- style>
注册界面:
- <template>
- <div class="login-wrap">
- <el-form class="login-container">
- <h1 class="title">用户注册h1>
- <el-form-item label="">
- <el-input type="text" v-model="username" placeholder="注册账号" autocomplete="off">el-input>
- el-form-item>
- <el-form-item label="">
- <el-input type="password" v-model="password" placeholder="注册密码" autocomplete="off">el-input>
- el-form-item>
- <el-form-item>
- <el-button type="warning" style="width:100%;" @click="doSubmit()">提交el-button>
- el-form-item>
- <el-row style="text-align: center;margin-top:-10px">
- <el-link type="primary">忘记密码el-link>
- <el-link type="primary" @click="gotoLogin()">用户注册el-link>
- el-row>
- el-form>
- div>
- template>
-
- <script>
- export default {
- name: 'Register',
- data() {
- return {
- username: '',
- password: ''
- }
- },
- methods: {
- gotoLogin() {
- this.$router.push("/");
- }
- }
- }
- script>
-
- <style scoped>
- .login-wrap {
- box-sizing: border-box;
- width: 100%;
- height: 100%;
- padding-top: 10%;
- ;
- /* background-color: #3b7cf5; */
- background-repeat: no-repeat;
- background-position: center right;
- background-size: 100%;
- }
-
- .login-container {
- border-radius: 10px;
- margin: 0px auto;
- width: 350px;
- padding: 30px 35px 15px 35px;
- border: 1px solid #eaeaea;
- text-align: left;
- background-color: rgba(229, 229, 229, 0.8);
- }
-
- .title {
- margin: 0px auto 40px auto;
- text-align: center;
- color: #0b0b0b;
- }
- style>
注1: