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> 
相关推荐
拾光拾趣录3 分钟前
给Electron-Claude应用构建全面的数据统计体系 - 从0到1的实践总结
前端·electron
changuncle17 分钟前
Angular初学者入门第一课——搭建并改造项目(精品)
javascript·ecmascript·angular.js
拾光拾趣录30 分钟前
8道题穿透前端原理层
前端·面试
海天胜景1 小时前
vue3 el-table 去除小数 并使用千分号
javascript·vue.js·elementui
cc蒲公英1 小时前
uniapp x swiper/image组件mode=“aspectFit“ 图片有的闪现后黑屏
java·前端·uni-app
前端小咸鱼一条1 小时前
React的介绍和特点
前端·react.js·前端框架
谢尔登1 小时前
【React】fiber 架构
前端·react.js·架构
哈哈哈哈哈哈哈哈8531 小时前
Vue3 的 setup 与 emit:深入理解 Composition API 的核心机制
前端
漫天星梦1 小时前
Vue2项目搭建(Layout布局、全局样式、VueX、Vue Router、axios封装)
前端·vue.js
ytttr8732 小时前
5G毫米波射频前端设计:从GaN功放到混合信号集成方案
前端·5g·生成对抗网络