vue3 element - plus 安装使用教程

下边是安装教程****element - plus 是针对 vue3 开发

一个 Vue 3 UI 框架 | Element Plus (element-plus.org)https://element-plus.org/zh-CN/

安装 element - plus ui 库

复制代码
# 选择一个你喜欢的包管理器

# NPM
$ npm install element-plus --save

# Yarn
$ yarn add element-plus

# pnpm
$ pnpm install element-plus

安装 element - plus icon 库 需要单独引入

复制代码
# 选择一个你喜欢的包管理器

# NPM
$ npm install @element-plus/icons-vue
# Yarn
$ yarn add @element-plus/icons-vue
# pnpm
$ pnpm install @element-plus/icons-vue

main.js 个人习惯 喜欢全局引入

复制代码
import { createApp } from 'vue'
import App from './App.vue'

// 引入ui 库
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

// 引入ui icon
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(ElementPlus)
app.mount('#app')

页面使用

复制代码
<template>
  <div class="bg">
    <div class="nav">
    <!-- 轮播图 -->
      <div class="block">
        <el-carousel trigger="click">
          <el-carousel-item v-for="item in 4" :key="item">
          </el-carousel-item>
        </el-carousel>
      </div>
     <!-- 表单 -->
      <div class="form">
        <h2 class="h2">欢迎登录</h2>
        <h6 class="p">左 右 软 件 后 勤 系 统  </h6>
        <el-form :model="ruleForm" :rules="rules" status-icon class="form-el">
          <el-form-item  prop="name">
            <el-input v-model="ruleForm.name" placeholder="请输入账号" prefix-icon="User"/> 
          </el-form-item>
          <el-form-item  prop="pass">
            <el-input v-model="ruleForm.pass" placeholder="请输入密码" prefix-icon="Lock" show-password  />
          </el-form-item>
        </el-form>
        <div class="form-but">
          <el-checkbox-group v-model="form.type">
        <el-checkbox label="记住密码" name="type" />
      </el-checkbox-group>
          <a href="https://www.baidu.com/" style="margin-left: 100px; text-decoration:none;">忘记密码?</a>
        </div>
        <el-button type="primary" style="width: 240px;margin-top: 250px;">登录</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import { reactive } from 'vue'
export default {
  name: 'HelloWorld',
  setup() {
    const form = reactive({
  type: [],
})
    const ruleForm = reactive({
      name: '',
      pass: ''
    })
    const rules = reactive({
      name: [
        { required: true, message: '请输入账号', trigger: 'blur' },
        { min: 3, max: 5, message: '账号3到5位', trigger: 'blur' },
      ],
      pass: [
        { required: true, message: '请输入密码', trigger: 'blur' },
        { min: 3, max: 5, message: '账号3到5位', trigger: 'blur' },
      ],
    })
    return {
      ruleForm,
      rules,
      form
    }
  }
}
</script>
<style setup>
.form-but{
  display: flex;
  left: 30px;
  top: 230px;
  position: absolute;
}
.form-el{
  width: 250px;
    left: 34px;
    top: 120px;
    position: absolute;
}
.h2{
  left: 30px;
  top: 20px;
  position: absolute;
}
.p{
  left: 30px;
  top: 55px;
  position: absolute;
  color: rgb(172, 172, 172);
}
.form{
  right: 30px;
  top: -30px;
  border-radius: 5px;
  padding: 30px 20px;
  position: absolute;
  margin: auto;
  width: 300px;
  height: 312px;
  background: rgb(255, 255, 255);
}
.block {
  width: 420px;
  height: 300px;
  top: 0;
  bottom: 0;
  position: absolute;
  margin: auto;
}
.el-carousel__item:nth-child(2n) {
  background-image: url('../assets/logo.png') ;
  background-position: center center;
  background-repeat: no-repeat;
}
.el-carousel__item:nth-child(2n + 1) {
  background-image: url('../assets/logo.png') ;
  background-position: center center;
  background-repeat: no-repeat;
}
.bg {
  width: 100%w;
  height: 45rem;
  background: url('../assets/QQ截图20230904182803.jpg');
}
.nav {
  width: 900px;
  height: 420px;
  background: url('../assets/QQ截图20230904182803.jpg');
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  position: absolute;
  margin: auto;
}
</style> 
相关推荐
前端君12 小时前
实现最大异步并发执行队列
javascript
Nan_Shu_61413 小时前
Web前端面试题(2)
前端
知识分享小能手13 小时前
React学习教程,从入门到精通,React 组件核心语法知识点详解(类组件体系)(19)
前端·javascript·vue.js·学习·react.js·react·anti-design-vue
蚂蚁RichLab前端团队14 小时前
🚀🚀🚀 RichLab - 花呗前端团队招贤纳士 - 【转岗/内推/社招】
前端·javascript·人工智能
孩子 你要相信光14 小时前
css之一个元素可以同时应用多个动画效果
前端·css
萌萌哒草头将军14 小时前
Oxc 和 Rolldown Q4 更新计划速览!🚀🚀🚀
javascript·vue.js·vite
huangql52014 小时前
npm 发布流程——从创建组件到发布到 npm 仓库
前端·npm·node.js
Qlittleboy14 小时前
uniapp如何使用本身的字体图标
javascript·vue.js·uni-app
Days205014 小时前
LeaferJS好用的 Canvas 引擎
前端·开源
小白菜学前端15 小时前
vue2 常用内置指令总结
前端·vue.js