首页 > 其他分享 >Element Plus中button按钮相关大全

Element Plus中button按钮相关大全

时间:2024-09-15 15:50:15浏览次数:3  
标签:Search 样式 text button Element Plus 按钮 type 图标

一、基本用法

使用 typeplainround 和 circle 来定义按钮的样式。

样式代码如下:

<template>
  <div class="mb-4">
    <el-button>Default</el-button>
    <el-button type="primary">Primary</el-button>
    <el-button type="success">Success</el-button>
    <el-button type="info">Info</el-button>
    <el-button type="warning">Warning</el-button>
    <el-button type="danger">Danger</el-button>
  </div>

  <div class="mb-4">
    <el-button plain>Plain</el-button>
    <el-button type="primary" plain>Primary</el-button>
    <el-button type="success" plain>Success</el-button>
    <el-button type="info" plain>Info</el-button>
    <el-button type="warning" plain>Warning</el-button>
    <el-button type="danger" plain>Danger</el-button>
  </div>

  <div class="mb-4">
    <el-button round>Round</el-button>
    <el-button type="primary" round>Primary</el-button>
    <el-button type="success" round>Success</el-button>
    <el-button type="info" round>Info</el-button>
    <el-button type="warning" round>Warning</el-button>
    <el-button type="danger" round>Danger</el-button>
  </div>

  <div>
    <el-button :icon="Search" circle />
    <el-button type="primary" :icon="Edit" circle />
    <el-button type="success" :icon="Check" circle />
    <el-button type="info" :icon="Message" circle />
    <el-button type="warning" :icon="Star" circle />
    <el-button type="danger" :icon="Delete" circle />
  </div>
</template>

<script lang="ts" setup>
import {
  Check,
  Delete,
  Edit,
  Message,
  Search,
  Star,
} from '@element-plus/icons-vue'
</script>

 二、禁用状态

可以使用 disabled 属性来定义按钮是否被禁用。

使用 disabled 属性来控制按钮是否为禁用状态。 该属性接受一个 Boolean 类型的值。

样式代码如下: 

<template>
  <div class="mb-4">
    <el-button disabled>Default</el-button>
    <el-button type="primary" disabled>Primary</el-button>
    <el-button type="success" disabled>Success</el-button>
    <el-button type="info" disabled>Info</el-button>
    <el-button type="warning" disabled>Warning</el-button>
    <el-button type="danger" disabled>Danger</el-button>
  </div>

  <div>
    <el-button plain disabled>Plain</el-button>
    <el-button type="primary" plain disabled>Primary</el-button>
    <el-button type="success" plain disabled>Success</el-button>
    <el-button type="info" plain disabled>Info</el-button>
    <el-button type="warning" plain disabled>Warning</el-button>
    <el-button type="danger" plain disabled>Danger</el-button>
  </div>
</template>

 三、链接按钮

新的 API link 于 2.2.1 版本时添加,你可以使用 type API 设置链接按钮的主题样式

样式代码如下: 

<template>
  <p>Basic link button</p>
  <div class="mb-4">
    <el-button
      v-for="button in buttons"
      :key="button.text"
      :type="button.type"
      link
    >
      {{ button.text }}
    </el-button>
  </div>

  <p>Disabled link button</p>
  <div>
    <el-button
      v-for="button in buttons"
      :key="button.text"
      :type="button.type"
      link
      disabled
    >
      {{ button.text }}
    </el-button>
  </div>
</template>

<script setup lang="ts">
const buttons = [
  { type: '', text: 'plain' },
  { type: 'primary', text: 'primary' },
  { type: 'success', text: 'success' },
  { type: 'info', text: 'info' },
  { type: 'warning', text: 'warning' },
  { type: 'danger', text: 'danger' },
] as const
</script>

 四、文字按钮

文字按钮在现在有了全新的设计样式。 2.2.0 如果您想要使用老版样式的按钮,可以考虑使用 Link 组件。

API也已更新,由于 type 属性会同时控制按钮的样式, 因此我们通过一个新的 API text: boolean 来控制文字按钮。

五、图标按钮

使用图标为按钮添加更多的含义。 你也可以单独使用图标不添加文字来节省显示区域占用。

使用 icon 属性来为按钮添加图标。 您可以在我们的 Icon 组件中找到所需图标。 通过向右方添加<i>标签来添加图标, 你也可以使用自定义图标。

样式代码如下: 

<template>
  <div>
    <el-button type="primary" :icon="Edit" />
    <el-button type="primary" :icon="Share" />
    <el-button type="primary" :icon="Delete" />
    <el-button type="primary" :icon="Search">Search</el-button>
    <el-button type="primary">
      Upload<el-icon class="el-icon--right"><Upload /></el-icon>
    </el-button>
  </div>
</template>
<script setup lang="ts">
import { Delete, Edit, Search, Share, Upload } from '@element-plus/icons-vue'
</script>

六、按钮组

以按钮组的方式出现,常用于多项类似操作。

使用 <el-button-group> 对多个按钮分组。

样式代码如下: 

<template>
  <el-button-group>
    <el-button type="primary" :icon="ArrowLeft">Previous Page</el-button>
    <el-button type="primary">
      Next Page<el-icon class="el-icon--right"><ArrowRight /></el-icon>
    </el-button>
  </el-button-group>

  <el-button-group class="ml-4">
    <el-button type="primary" :icon="Edit" />
    <el-button type="primary" :icon="Share" />
    <el-button type="primary" :icon="Delete" />
  </el-button-group>
</template>

<script setup lang="ts">
import {
  ArrowLeft,
  ArrowRight,
  Delete,
  Edit,
  Share,
} from '@element-plus/icons-vue'
</script>

七、加载状态按钮

点击按钮来加载数据,并向用户反馈加载状态。

通过设置 loading 属性为 true 来显示加载中状态。

八、调整尺寸

除了默认的大小,按钮组件还提供了几种额外的尺寸可供选择,以便适配不同的场景。

使用 size 属性额外配置尺寸,可使用 largesmall两种值。

样式代码如下: 

<template>
  <div class="flex flex-wrap items-center mb-4">
    <el-button size="large">Large</el-button>
    <el-button>Default</el-button>
    <el-button size="small">Small</el-button>
    <el-button size="large" :icon="Search">Search</el-button>
    <el-button :icon="Search">Search</el-button>
    <el-button size="small" :icon="Search">Search</el-button>
  </div>
  <div class="flex flex-wrap items-center mb-4">
    <el-button size="large" round>Large</el-button>
    <el-button round>Default</el-button>
    <el-button size="small" round>Small</el-button>
    <el-button size="large" :icon="Search" round>Search</el-button>
    <el-button :icon="Search" round>Search</el-button>
    <el-button size="small" :icon="Search" round>Search</el-button>
  </div>
  <div class="flex flex-wrap items-center">
    <el-button :icon="Search" size="large" circle />
    <el-button :icon="Search" circle />
    <el-button :icon="Search" size="small" circle />
  </div>
</template>

<script setup lang="ts">
import { Search } from '@element-plus/icons-vue'
</script>

九、Tag

可以自定义元素标签。例如,按钮,div,路由链接,nuxt链接。

十、自定义颜色

可以自定义按钮的颜色。

我们将自动计算按钮处于 hover 和 active 状态时的颜色。

标签:Search,样式,text,button,Element,Plus,按钮,type,图标
From: https://blog.csdn.net/m0_75068951/article/details/142261682

相关文章

  • Elment Plus数据展示 | Progress进度条(超详细!)
            用于展示操作进度,告知用户当前状态和预期。一、直线进度条        Progress组件设置 percentage 属性即可,表示进度条对应的百分比。该属性必填,并且必须在 0-100 的范围内。你可以通过设置 format 来自定义文字显示的格式。     运行......
  • C++ Primer Plus 第六版中文版(上)
    参考资料:《C++PrimerPlus第六版中文版》笔记作者:Mr.Crocodile欢迎转载文章目录开始学习C++头文件命名规定名称空间`cout`、`cin`函数处理数据简单变量变量命名规则整型运算符`sizeof`和头文件climitsclimits中的符号常量变量初始化整型字面量整型字面量后缀char......
  • mybatis plus多表查询的扩展
    mybatisplus提供了简单的CURD操作,但是有时我们的业务需要要求进行多表查询,这个时候,我们就需要加入多表查询的扩展了。 mybatis-plus-join,基于mybatis-plus的所有优点,然后还支持连表查询,还支持一对多,一对一的查询。mybatis-plus-join是mybatisplus的一个多表插件,上手简单,几分钟就......
  • 【前端UI框架】VUE ElementUI 离线文档 可不联网打开
    【前端UI框架】VUEElementUI离线文档可不联网打开Element-Theworld'smostpopularVueUIframeworkElement-Theworld'smostpopularVueUIframework离线文档下载地址文档制作第一步:克隆源代码Gitee地址:https://gitee.com/ElemeFE/element.gitGitHub地址:https:......
  • cpp primer plus 第七章
    7.1函数基本知识7.1.1定义函数函数分为两类:有返回值与无返回值的函数。对于有返回值的函数,必须使用返回语句,将值返回给调用函数。若函数包含多条返回语句,则函数在执行第一条返回语句后结束。7.1.2函数原型声明函数如果在main函数后方,则在前面声明函数(复制函数定义中的......
  • SpringBoot:Web开发(基于SpringBoot使用MyBatis-Plus+JSP开发)
    目录前期准备构建项目(IDEA2023.1.2,JDK21,SpringBoot3.3.3)添加启动器Model准备这里我们利用MybatisX插件生成我们所需要的实体类、数据访问层以及服务层注意选择MyBatis-Plus3以及Lombok然后再在service接口中定义我们所需要的方法以及实现类(利用MyBatis-Plus省去我们......
  • 尤雨溪推荐的拖拽插件,支持Vue2/Vue3 VueDraggablePlus
    大家好,我是「前端实验室」爱分享的了不起~今天在网上看到尤雨溪推荐的这款拖拽组件,试了一下非常不错,这里推荐给大家。说到拖拽工具库,非大名鼎鼎的的Sortablejs莫属。它是前端领域比较知名的,且功能强大的工具。但我们直接使用Sortablejs的情况很少,一般都是使用基于它的......
  • elementUI--el-form表单数据校验
    一、普通的值类型的数据校验①设置 el-form-item的prop 值与 formdata中定义的key 保持一致`②如果rules需要通过el-form统一设置,rules的key 定义也与prop保持一致(如果不一致,需要在el-form-item中手动指定)③复杂的校验函数可通过 validator 单独定义<el-for......
  • 标准的vue3 elementplus格式,不用export default
    <template><div><!--查询表单--><el-form:inline="true":model="filters"class="demo-form-inline"><el-form-itemlabel="产品料号"><el-inputv-model="filters.......
  • 微信小程序去除button边框
    微信小程序使用button按钮会带有默认的边框,按设计稿写样式通常要去掉这个,一些特殊操作也不能显示这个边框✨两步就可以去掉1、加上plain属性plain="true"或者只写plain都行<buttonplain="true">按钮</button>2、对按钮样式进行修改button[plain]{border:0......