Element UI搭建使用过程

本章内容基于上一篇---Vue-cli搭建项目基础版

Vue-cli搭建项目----基础版-CSDN博客

官网地址:Element - The world's most popular Vue UI framework

介绍:完全基于Vue.js ,用于快速搭建用户界面.

第一步:安装ElementUI

在终端输入

javascript 复制代码
npm i element-ui -S

在main.js输入

在 main.js 中导入以下内容:

javascript 复制代码
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

如图所示

导入成功后

在Login.vue文件中随便导入一个组件检验是否成功

Login导入如图所示

导入成功

测试成功

第二步:搭建登陆界面

将Login.vue添加如下css代码

javascript 复制代码
<!-- 一个.vue文件是一个组件,可以理解为一个页面,但是和页面不同 
  内容都写在一个template标签中,
  template标签必须有一个根标签
-->
<template>
	 <div class="login_container">
	     <!-- 登录盒子-->
	     <div class="login_box">
	          <!-- 头像盒子-->
	          <div class="img_box">
	                <img src="./assets/logo.png" />
	          </div>
			  
			
				
		
	     </div>
	  </div>
</template>

<script>
/* 导出组件,并为组件定义数据,函数,生命周期函数 */
 export default{
	 data(){
		 return{
			 
		 }
	 },
	 methods:{
		 
	 }
 }
</script>

<style>
  .login_container{
    height: 100vh;
    margin: 0px;
    padding: 0px;
	background-image: url(assets/bg.jpg);
  }

    .login_box{
      width: 450px;
      height: 350px;
      background-color: #fff;
      border-radius: 10px;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%,-50%);
	  opacity: 0.95;
    }

    .img_box{
       width: 130px;
       height: 130px;
       position: absolute;
       left: 50%;
       transform: translate(-50%,-50%);
       background-color: #fff;
       border-radius: 50%;
       padding: 5px;
       border: 1px solid #eee;
    }
    
    .img_box img{
         width: 100%;
         height: 100%;
         border-radius: 50%;
         background-color: #eee;
     }
</style>

图片在asses中插入一张图.

呈现出如图所示效果

接下来在中间加入表单

根据需求在ElementUI官网赋值相应的代码组件

login.vue组件如下

javascript 复制代码
<!-- 一个.vue文件是一个组件,可以理解为一个页面,但是和页面不同 
  内容都写在一个template标签中,
  template标签必须有一个根标签
-->
<template>
	 <div class="login_container">
	     <!-- 登录盒子-->
	     <div class="login_box">
	          <!-- 头像盒子-->
	          <div class="img_box">
	                <img src="./assets/logo.png" />
	          </div>
			  
			<div style="margin-top: 100px; padding-right: 20px;">
				<el-form ref="form" label-width="80px">
					 <el-form-item label="账号">
					    <el-input v-model ="account"></el-input>
					  </el-form-item>
					  <el-form-item label="密码">
					     <el-input v-model = "passworld" show-password></el-input>
					   </el-form-item>
					   <el-button type="primary" @click="login()">登录</el-button>
					       <el-button>取消</el-button>
					</el-form>
			</div>
				
		
	     </div>
	  </div>
</template>

<script>
/* 导出组件,并为组件定义数据,函数,生命周期函数 */
 export default{
	 data(){
		 return{
			 account :"",
			 passworld:""
		 }
	 },
	 methods:{
		 login()//与数据库进行交互
		 {
			 //验证账号和密码不能为空
			 if(this.account.length==0){
				  this.$message({
				           showClose: true,
				           message: '账号不能为空',
				           type: 'warning',
						 });
						      return;
						 }
						 if(this.passworld.length==0){
						 				  this.$message({
						 				           showClose: true,
						 				           message: '密码不能为空',
						 				           type: 'warning',
						 				         });
												    return;
													}
								//后端相应一个结果
								this.$router.push("/main");				 						 
			 }
		 }
	 }	
</script>

<style>
  .login_container{
    height: 100vh;
    margin: 0px;
    padding: 0px;
	background-image: url(assets/bg.jpg);
  }

    .login_box{
      width: 450px;
      height: 350px;
      background-color: #fff;
      border-radius: 10px;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%,-50%);
	  opacity: 0.95;
    }

    .img_box{
       width: 130px;
       height: 130px;
       position: absolute;
       left: 50%;
       transform: translate(-50%,-50%);
       background-color: #fff;
       border-radius: 50%;
       padding: 5px;
       border: 1px solid #eee;
    }
    
    .img_box img{
         width: 100%;
         height: 100%;
         border-radius: 50%;
         background-color: #eee;
     }
</style>

实现效果

相关推荐
W***r261 小时前
服务器处理请求:服务器解析请求并返回响应
ui
工业HMI实战笔记2 小时前
拯救HMI×施耐德电气|以AI重塑工业人机交互新范式
人工智能·ui·信息可视化·自动化·人机交互·交互
AI陪跑3 小时前
AI助力搭建 ant design 6 的 可视化编辑UI设计器
ui
小雨下雨的雨3 小时前
Flutter跨平台开发实战: 鸿蒙与循环交互艺术:ListView 的视口循环与内存复用
flutter·ui·华为·交互·harmonyos·鸿蒙系统
向上的车轮3 小时前
Zed 项目GPUI :用 Rust + GPU 渲染的现代化 UI 框架
开发语言·ui·rust
豆几的窝13 小时前
230+效率功能2026AI插件脚本大合集V7.0最新中文版支持Illustrator 2026-CS6 Win/Mac
ui·illustrator
我命由我123451 天前
Photoshop - Photoshop 工具栏(58)锐化工具
学习·ui·职场和发展·求职招聘·职场发展·学习方法·photoshop
小雨下雨的雨1 天前
Flutter 框架跨平台鸿蒙开发 —— Flex 控件之响应式弹性布局
flutter·ui·华为·harmonyos·鸿蒙系统
沐墨染1 天前
敏感词智能检索前端组件设计:树形组织过滤与多维数据分析
前端·javascript·vue.js·ui·数据挖掘·数据分析
小雨下雨的雨2 天前
Flutter 框架跨平台鸿蒙开发 —— Center 控件之完美居中之道
flutter·ui·华为·harmonyos·鸿蒙