UI 框架:Element-plus组件库(一)

简介: 在现代Web开发中,用户界面的设计与交互体验至关重要。随着前端技术的迅速发展,各种UI框架层出不穷,旨在提升开发效率和用户体验。其中,Element Plus作为一款基于Vue 3的组件库,因其简洁优雅的设计和丰富的功能而备受欢迎。Element Plus不仅提供了众多高质量的组件,还注重与开发者的友好互动,使得即使是初学者也能快速上手。在本系列文章中,我们将深入探讨Element Plus的各个组件及其应用,通过实例演示如何有效利用该框架构建美观且功能强大的用户界面。

引言


在现代Web开发中,用户界面的设计与交互体验至关重要。随着前端技术的迅速发展,各种UI框架层出不穷,旨在提升开发效率和用户体验。其中,Element Plus作为一款基于Vue 3的组件库,因其简洁优雅的设计和丰富的功能而备受欢迎。

Element Plus不仅提供了众多高质量的组件,还注重与开发者的友好互动,使得即使是初学者也能快速上手。在本系列文章中,我们将深入探讨Element Plus的各个组件及其应用,通过实例演示如何有效利用该框架构建美观且功能强大的用户界面。


使用

Plain Text
$ pnpm install element-plus --save
$ yarn add element-plus
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'
const app = createApp(App)
app.use(ElementPlus)
app.mount('#app')
图标
Plain Text
$ npm install @element-plus/icons-vue
# Yarn
$ yarn add @element-plus/icons-vue
```Plain Text 使用 import * as ElementPlusIconsVue from '@element-plus/icons-vue'
const app = createApp(App) for (const [key, component] of Object.entries(ElementPlusIconsVue)) {   app.component(key, component) }
```

输入框的使用

:prefix-icon

<el-input v-model="form.password" :type="passwordType" :prefix-icon="Search"></el-input>

:suffix-icon="Search"

显示   密码

:show-password="true"

:show-password="show"
<template>
    <div class="login_page">
        <div class="login_info">
            <el-form label-width="auto" :model="formLabelAlign" style="max-width: 800px">
                <el-form-item>
                    <el-input v-model="formLabelAlign.account" placeholder="请输入账号" type="text" />
                </el-form-item>
                <el-form-item>
                    <el-input v-model="formLabelAlign.password" placeholder="请输入密码" :type="password_type">
                        <template v-slot:suffix>
                            <el-icon :size="20" @click="show_password">
                                <component :is="show?icon_list.icon_view:icon_list.icon_hide" />
                            </el-icon>
                        </template>
                    </el-input>
                </el-form-item>
                <el-form-item class="login_btn">
                    <el-button type="primary">登录</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>
<script setup>
    import {
        reactive,
        ref
    } from 'vue'
    const password_type = ref("password")
    const formLabelAlign = reactive({
        account: '',
        password: '',
    })
    let show = ref(false)
    const show_password = () => {
        if (show.value) {
            password_type.value = "text"
        } else {
            password_type.value = "password"
        }
        show.value = !show.value
    }
    const icon_list = {
        icon_hide: "hide",
        icon_view: "view"
    }
</script>
<style scoped lang="scss">
    .login_page {
        display: flex;
        justify-content: center;
        /* 水平居中 */
        align-items: center;
        /* 垂直居中 */
        background: linear-gradient(to bottom right, #0081f1 30%, #f7182e 60%);
        width: 100%;
        /* 设置宽度为100% */
        height: 99vh;
        /* 设置高度为视口高度 */
    }
    .login_info {
        width: 400px;
        padding: 20px;
        border: 0.7px solid linear-gradient(to bottom right, #0081f1 30%, #f7182e 60%);
        border-radius: 5px;
        box-shadow: 1px 1px 3px;
    }
    .login_btn button {
        margin: 0 auto;
        width: 100%;
    }
</style>
<template>
    <div class="login_page">
        <div class="login_info">
            <el-form label-width="auto" :model="formLabelAlign" style="max-width: 800px">
                <el-form-item>
                    <el-input v-model="formLabelAlign.account" placeholder="请输入账号" type="text" />
                </el-form-item>
                <el-form-item>
                    <el-input v-model="formLabelAlign.password" show-password="true" placeholder="请输入密码"
                        type="password">
                    </el-input>
                </el-form-item>
                <el-form-item class="login_btn">
                    <el-button type="primary">登录</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>
<script setup>
    import {
        reactive,
        ref
    } from 'vue'
    const password_type = ref("password")
    const formLabelAlign = reactive({
        account: '',
        password: '',
    })
</script>
<style scoped lang="scss">
    .login_page {
        display: flex;
        justify-content: center;
        /* 水平居中 */
        align-items: center;
        /* 垂直居中 */
        background: linear-gradient(to bottom right, #0081f1 30%, #f7182e 60%);
        width: 100%;
        /* 设置宽度为100% */
        height: 99vh;
        /* 设置高度为视口高度 */
    }
    .login_info {
        width: 400px;
        padding: 20px;
        border: 0.7px solid linear-gradient(to bottom right, #0081f1 30%, #f7182e 60%);
        border-radius: 5px;
        box-shadow: 1px 1px 3px;
    }
    .login_btn button {
        margin: 0 auto;
        width: 100%;
    }
</style>


验证的清空

formEl.resetFields()  的使用

<el-form :model="form" :rules="rules" ref="formRef">
        用 ref  绑定 formRef
        const formRef = ref(null);

addStudent 中 定义 了 一个 方法

使用 如下

const addStudent = (test) => {
      resetForm(test.formRef)
}

清空  代码

const resetForm = (formEl) => {
    if (!formEl) return
    formEl.resetFields()
}

调用  传参 为

@click="addStudent($refs)

简单使用

<el-button @click="resetForm(formRef)">重置</el-button>
const resetForm = (formEl) => {
    if (!formEl) return
    formEl.resetFields()
}

轮播图

<template>
    <div class="home-banner">
        <el-carousel height="500px">
            <el-carousel-item v-for="item in 4" :key="item.id">
                <img src="../assets/images/logo.png" alt="">
            </el-carousel-item>
        </el-carousel>
    </div>
</template>
<script  setup>
</script>
<style scoped></style>


面包屑

<template>
    <div class="bread-container">
        <el-breadcrumb separator=">">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item v-for="(i, index) in item">{{ i.name }}</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
</template>
<script  setup>
let item = [
    {
        id: 1,
        name: 'home',
    },
    {
        id: 2,
        name: 'category',
    },
    {
        id: 3,
        name: 'settings',
    }];
</script>
<style scoped></style>

导航激活

在RouterLink里面配置 组件默认激活类名

设置 active-class 属性 设置对应的 类名 即可
<RouterLink active-class="active" :to="/test">
  {{item.name}}
  <RouterLink>
    .active{
      color:red,
        border-bottom:1px solid red}


骨架屏幕

skeleton

可以  的 样式 有

image.png


简单使用

<template>
  <el-skeleton style="width: 240px">
    <template #template>
      <el-skeleton-item variant="image" style="width: 240px; height: 240px" />
      <el-skeleton-item variant="text" style="width: 30%" />
    </template>
  </el-skeleton>
  <el-skeleton style="--el-skeleton-circle-size: 100px">
    <template #template>
      <el-skeleton-item variant="circle" />
    </template>
  </el-skeleton>
</template>
<script setup lang="ts">
</script>



简单的菜单

<template>
      <el-menu
          active-text-color="#ffd04b"
          background-color="#545c64"
          class="el-menu-vertical-demo"
          default-active="2"
          text-color="#fff"
      >
        <el-sub-menu index="1">
          <template #title>
            <el-icon><location /></el-icon>
            <span>Navigator One</span>
          </template>
          <el-menu-item-group title="Group One">
            <el-menu-item index="1-1">item one</el-menu-item>
            <el-menu-item index="1-2">item two</el-menu-item>
          </el-menu-item-group>
       </el-sub-menu>
      </el-menu>
</template>
<script lang="ts" setup>
import {
  Location,
} from '@element-plus/icons-vue'
</script>


table里面的tree

<template>
  <div>
    <el-table
        :data="tableData"
        style="width: 100%; margin-bottom: 20px"
        row-key="id"
        border
    >
      <el-table-column prop="date" label="Date" sortable />
      <el-table-column prop="name" label="Name" sortable />
      <el-table-column prop="address" label="Address" sortable />
    </el-table>
  </div>
</template>
<script lang="ts" setup>
interface User {
  id: number
  date: string
  name: string
  address: string
  hasChildren?: boolean
  children?: User[]
}
const tableData: User[] = [
  {
    id: 1,
    date: '2016-05-02',
    name: 'wangxiaohu',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    id: 2,
    date: '2016-05-04',
    name: 'wangxiaohu',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    id: 3,
    date: '2016-05-01',
    name: 'wangxiaohu',
    address: 'No. 189, Grove St, Los Angeles',
    children: [
      {
        id: 31,
        date: '2016-05-01',
        name: 'wangxiaohu',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 32,
        date: '2016-05-01',
        name: 'wangxiaohu',
        address: 'No. 189, Grove St, Los Angeles',
      },
    ],
  },
  {
    id: 4,
    date: '2016-05-03',
    name: 'wangxiaohu',
    address: 'No. 189, Grove St, Los Angeles',
  },
]
</script>


图标

<ElIcon :size="30" color="hotpink">
          <edit />
        </ElIcon>


目录
打赏
0
0
0
0
42
分享
相关文章
探索鸿蒙新世界:ArkUI框架实战指南,解锁HarmonyOS应用UI设计的无限可能!
【10月更文挑战第19天】ArkUI框架是华为鸿蒙系统中用于开发用户界面的核心工具,支持ArkTS和eTS两种开发语言。本文介绍了ArkUI的基本概念、组件使用、布局管理和状态管理,通过示例代码帮助开发者轻松构建美观、高效的跨设备UI。
367 3
ES6 awaitRust UI 框架
ES6 awaitRust UI 框架
45 0
electron ui框架
Electron是一个使用JavaScript, HTML和CSS等前端技术构建跨平台桌面应用程序的框架。
253 0
FirstUI:Deepseek能帮我们做很多事情,而这款开源框架专为开发者设计的开源UI框架,让你的项目加速起飞
嗨,大家好,我是小华同学。今天为大家介绍一个轻量级、响应式的前端UI框架——FirstUI。它提供丰富的组件库,包括按钮、输入框、下拉菜单等,帮助开发者快速构建美观、功能丰富的用户界面。FirstUI的核心理念是“简单、快速、高效”,适合各种Web应用开发,如企业网站、电商平台和个人博客。其体积小、加载快,支持响应式设计,并且易于定制。FirstUI拥有活跃的社区支持,开发者可以轻松找到帮助并分享经验。欢迎关注我们,获取更多优质开源项目和高效工作学习方法。
Midscene.js:AI 驱动的 UI 自动化测试框架,支持自然语言交互,生成可视化报告
Midscene.js 是一款基于 AI 技术的 UI 自动化测试框架,通过自然语言交互简化测试流程,支持动作执行、数据查询和页面断言,提供可视化报告,适用于多种应用场景。
706 1
Midscene.js:AI 驱动的 UI 自动化测试框架,支持自然语言交互,生成可视化报告
【入门思路】基于Python+Unittest+Appium+Excel+BeautifulReport的App/移动端UI自动化测试框架搭建思路
本文重点讲解如何搭建App自动化测试框架的思路,而非完整源码。主要内容包括实现目的、框架设计、环境依赖和框架的主要组成部分。适用于初学者,旨在帮助其快速掌握App自动化测试的基本技能。文中详细介绍了从需求分析到技术栈选择,再到具体模块的封装与实现,包括登录、截图、日志、测试报告和邮件服务等。同时提供了运行效果的展示,便于理解和实践。
214 4
【入门思路】基于Python+Unittest+Appium+Excel+BeautifulReport的App/移动端UI自动化测试框架搭建思路
小程序常见的 UI 框架
【10月更文挑战第17天】小程序 UI 框架为开发者提供了便捷的工具和资源,帮助他们快速构建高质量的小程序界面。在选择框架时,需要综合考虑各种因素,以找到最适合项目的解决方案。随着技术的不断进步,UI 框架也将不断发展和创新,为小程序开发带来更多的便利和可能性。
273 2
使用Radzen Blazor组件库开发的基于ABP框架炫酷UI主题
【10月更文挑战第20天】本文介绍了使用 Radzen Blazor 组件库开发基于 ABP 框架的炫酷 UI 主题的步骤。从准备工作、引入组件库、设计主题、集成到 ABP 框架,再到优化和调试,详细讲解了每个环节的关键点和注意事项。通过这些步骤,你可以打造出高性能、高颜值的应用程序界面。
122 1
UI 框架:nav-ui&uni-ui&vant
本文档介绍了`nav-ui`、`uni-ui`和`vant`三个UI库的基本使用方法,包括图标、表格和树的使用示例,以及如何在项目中安装和配置这些UI组件。对于`nav-ui`,详细说明了图标组件的安装与使用,包括本地图标和第三方图标库的集成方式。`uni-ui`部分则重点讲解了CSS的使用方法。最后,`vant`部分提供了从项目创建到组件安装的具体步骤,以及如何将下载的组件正确地集成到项目中。
220 4

热门文章

最新文章

  • 1
    【11】flutter进行了聊天页面的开发-增加了即时通讯聊天的整体页面和组件-切换-朋友-陌生人-vip开通详细页面-即时通讯sdk准备-直播sdk准备-即时通讯有无UI集成的区别介绍-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草Alex
    8
  • 2
    Magma:微软放大招!新型多模态AI能看懂视频+浏览网页+UI交互+控制机器人,数字世界到物理现实无缝衔接
    31
  • 3
    【02】Java+若依+vue.js技术栈实现钱包积分管理系统项目-商业级电玩城积分系统商业项目实战-ui设计图figmaUI设计准备-figma汉化插件-mysql数据库设计-优雅草卓伊凡商业项目实战
    6
  • 4
    如何在React.js中使用Shadcn/UI
    74
  • 5
    移动端UI名词 - AxureMost
    2
  • 6
    unity判断鼠标在不在UI上
    12
  • 7
    Flame:开源AI设计图转代码模型!生成React组件,精准还原UI+动态交互效果
    120
  • 8
    Vue Amazing UI 组件库(Vue3+TypeScript+Vite 等最新技术栈开发)
    11
  • 9
    FirstUI:Deepseek能帮我们做很多事情,而这款开源框架专为开发者设计的开源UI框架,让你的项目加速起飞
    23
  • 10
    【03】鸿蒙实战应用开发-华为鸿蒙纯血操作系统Harmony OS NEXT-测试hello word效果-虚拟华为手机真机环境调试-为DevEco Studio编译器安装中文插件-测试写一个滑动块效果-介绍诸如ohos.ui等依赖库-全过程实战项目分享-从零开发到上线-优雅草卓伊凡
    7