Button 按钮 #
常用的操作按钮。
基础用法 #
输入 #
<demo src="../component/button.vue" desc="使用 `type`、`plain`、`round` 和 `circle` 来定义按钮的样式。"></demo>
输出 #
使用
type
、plain
、round
和 circle
来定义按钮的样式。<template>
<el-row 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>
</el-row>
<el-row 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>
</el-row>
<el-row 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>
</el-row>
<el-row>
<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 />
</el-row>
</template>
<script lang="ts" setup>
import { Check, Delete, Edit, Message, Search, Star } from "@element-plus/icons-vue";
</script>
<style>
.mb-4 {
margin-bottom: 1rem;
}
</style>
显示代码
禁用状态 #
输入 #
<demo src="../component/button-disabled.vue" desc="使用 `disabled`来定义按钮的禁用。"></demo>
输出 #
使用
disabled
来定义按钮的禁用。<template>
<el-row 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>
</el-row>
<el-row>
<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>
</el-row>
</template>
显示代码
链接按钮 #
WARNING
type="text"
已被 废弃,将于版本 3.0.0 时 移除,请考虑切换至新的 API。
新的 API link
于 2.2.1 版本添加,同时可以使用 type API 设置链接按钮的主题样式。
输入 #
<demo src="../component/button-link.vue"></demo>
输出 #
Basic link button
Disabled link button
<template>
<p>Basic link button</p>
<div class="flex justify-space-between mb-4 flex-wrap gap-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 class="flex justify-space-between flex-wrap gap-4">
<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>
显示代码
自定义颜色 #
除了默认的大小,按钮组件还提供了几种额外的尺寸可供选择,以便适配不同的场景。
使用 size
属性额外配置尺寸,可使用 large
和small
两种值。
输入 #
<demo src="../component/button-size.vue"></demo>
输出 #
<template>
<el-row>
<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>
</el-row>
<el-row class="my-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>
</el-row>
<el-row>
<el-button :icon="Search" size="large" circle />
<el-button :icon="Search" circle />
<el-button :icon="Search" size="small" circle />
</el-row>
</template>
<script setup lang="ts">
import { Search } from "@element-plus/icons-vue";
</script>
显示代码
Button 属性 #
属性名 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
size | 尺寸 | string | large / default /small | — |
type | 类型 | string | primary / success / warning / danger / info / text | — |
round | 是否为圆角按钮 | boolean | — | false |
circle | 是否为圆形按钮 | boolean | — | false |