Button 按钮
常用的操作按钮。
基础用法
使用 type、plain、round 和 circle 来定义按钮的样式。
vue
<template>
<el-row class="mb-4">
<qy-button>Default</qy-button>
<qy-button type="primary">Primary</qy-button>
<qy-button type="success">Success</qy-button>
<qy-button type="info">Info</qy-button>
<qy-button type="warning">Warning</qy-button>
<qy-button type="danger">Danger</qy-button>
</el-row>
<el-row class="mb-4">
<qy-button plain>Plain</qy-button>
<qy-button type="primary" plain>Primary</qy-button>
<qy-button type="success" plain>Success</qy-button>
<qy-button type="info" plain>Info</qy-button>
<qy-button type="warning" plain>Warning</qy-button>
<qy-button type="danger" plain>Danger</qy-button>
</el-row>
<el-row class="mb-4">
<qy-button round>Round</qy-button>
<qy-button type="primary" round>Primary</qy-button>
<qy-button type="success" round>Success</qy-button>
<qy-button type="info" round>Info</qy-button>
<qy-button type="warning" round>Warning</qy-button>
<qy-button type="danger" round>Danger</qy-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><template>
<el-row class="mb-4">
<qy-button>Default</qy-button>
<qy-button type="primary">Primary</qy-button>
<qy-button type="success">Success</qy-button>
<qy-button type="info">Info</qy-button>
<qy-button type="warning">Warning</qy-button>
<qy-button type="danger">Danger</qy-button>
</el-row>
<el-row class="mb-4">
<qy-button plain>Plain</qy-button>
<qy-button type="primary" plain>Primary</qy-button>
<qy-button type="success" plain>Success</qy-button>
<qy-button type="info" plain>Info</qy-button>
<qy-button type="warning" plain>Warning</qy-button>
<qy-button type="danger" plain>Danger</qy-button>
</el-row>
<el-row class="mb-4">
<qy-button round>Round</qy-button>
<qy-button type="primary" round>Primary</qy-button>
<qy-button type="success" round>Success</qy-button>
<qy-button type="info" round>Info</qy-button>
<qy-button type="warning" round>Warning</qy-button>
<qy-button type="danger" round>Danger</qy-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>链接按钮
Basic link button
Disabled link button
vue
<template>
<p>Basic link button</p>
<div class="flex justify-space-between mb-4 flex-wrap gap-4">
<qy-button
v-for="button in buttons"
:key="button.text"
:type="button.type"
link
>{{ button.text }}</qy-button
>
</div>
<p>Disabled link button</p>
<div class="flex justify-space-between flex-wrap gap-4">
<qy-button
v-for="button in buttons"
:key="button.text"
:type="button.type"
link
disabled
>{{ button.text }}</qy-button
>
</div>
</template>
<script setup>
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' }
]
</script><template>
<p>Basic link button</p>
<div class="flex justify-space-between mb-4 flex-wrap gap-4">
<qy-button
v-for="button in buttons"
:key="button.text"
:type="button.type"
link
>{{ button.text }}</qy-button
>
</div>
<p>Disabled link button</p>
<div class="flex justify-space-between flex-wrap gap-4">
<qy-button
v-for="button in buttons"
:key="button.text"
:type="button.type"
link
disabled
>{{ button.text }}</qy-button
>
</div>
</template>
<script setup>
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' }
]
</script>加载状态按钮
vue
<template>
<qy-button type="primary" loading>Loading</qy-button>
<qy-button type="primary" :loading-icon="Eleme" loading>Loading</qy-button>
<qy-button type="primary" loading>
<template #loading>
<div class="custom-loading">
<svg class="circular" viewBox="-10, -10, 50, 50">
<path
class="path"
d="
M 30 15
L 28 17
M 25.61 25.61
A 15 15, 0, 0, 1, 15 30
A 15 15, 0, 1, 1, 27.99 7.5
L 15 15
"
style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"
/>
</svg>
</div>
</template>
Loading
</qy-button>
</template>
<script setup>
import { Eleme } from '@element-plus/icons-vue'
</script>
<style scoped>
.qy-button .custom-loading .circular {
margin-right: 6px;
width: 18px;
height: 18px;
animation: loading-rotate 2s linear infinite;
}
.qy-button .custom-loading .circular .path {
animation: loading-dash 1.5s ease-in-out infinite;
stroke-dasharray: 90, 150;
stroke-dashoffset: 0;
stroke-width: 2;
stroke: var(--qy-button-text-color);
stroke-linecap: round;
}
</style><template>
<qy-button type="primary" loading>Loading</qy-button>
<qy-button type="primary" :loading-icon="Eleme" loading>Loading</qy-button>
<qy-button type="primary" loading>
<template #loading>
<div class="custom-loading">
<svg class="circular" viewBox="-10, -10, 50, 50">
<path
class="path"
d="
M 30 15
L 28 17
M 25.61 25.61
A 15 15, 0, 0, 1, 15 30
A 15 15, 0, 1, 1, 27.99 7.5
L 15 15
"
style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"
/>
</svg>
</div>
</template>
Loading
</qy-button>
</template>
<script setup>
import { Eleme } from '@element-plus/icons-vue'
</script>
<style scoped>
.qy-button .custom-loading .circular {
margin-right: 6px;
width: 18px;
height: 18px;
animation: loading-rotate 2s linear infinite;
}
.qy-button .custom-loading .circular .path {
animation: loading-dash 1.5s ease-in-out infinite;
stroke-dasharray: 90, 150;
stroke-dashoffset: 0;
stroke-width: 2;
stroke: var(--qy-button-text-color);
stroke-linecap: round;
}
</style>Button API
Button Attributes
| Name | Description | Type | Default |
|---|---|---|---|
| size | button size | ^[enum]'large'| 'default'| 'small' | — |
| type | button type | ^[enum]'primary'| 'success'| 'warning'| 'danger'| 'info'| 'text'(delete) | — |
| plain | determine whether it's a plain button | ^[boolean] | false |
| text | determine whether it's a text button | ^[boolean] | false |
| bg | determine whether the text button background color is always on | ^[boolean] | false |
| link | determine whether it's a link button | ^[boolean] | false |
| round | determine whether it's a round button | ^[boolean] | false |
| circle | determine whether it's a circle button | ^[boolean] | false |
| loading | determine whether it's loading | ^[boolean] | false |
| loading-icon | customize loading icon component | ^[string] / ^[Component] | Loading |
| disabled | disable the button | ^[boolean] | false |
| icon | icon component | ^[string] / ^[Component] | — |
| autofocus | same as native button's autofocus | ^[boolean] | false |
| native-type | same as native button's type | ^[enum]'button'| 'submit'| 'reset' | button |
| auto-insert-space | automatically insert a space between two chinese characters | ^[boolean] | — |
| color | custom button color, automatically calculate hover and active color | ^[string] | — |
| dark | dark mode, which automatically converts color to dark mode colors | ^[boolean] | false |
Button Slots
| Name | Description |
|---|---|
| default | customize default content |
| loading | customize loading component |
| icon | customize icon component |
Button Exposes
| Name | Description | Type |
|---|---|---|
| ref | button html element | ^[object]Ref<HTMLButtonElement> |
| size | button size | ^[object]ComputedRef<'' | 'small' | 'default' | 'large'> |
| type | button type | ^[object]ComputedRef<'' | 'default' | 'primary' | 'success' | 'warning' | 'info' | 'danger' | 'text'> |
| disabled | button disabled | ^[object]ComputedRef<boolean> |
| shouldAddSpace | whether adding space | ^[object]ComputedRef<boolean> |
ButtonGroup API
ButtonGroup Attributes
| Name | Description | Type | Default |
|---|---|---|---|
| size | control the size of buttons in this button-group | ^[enum]'large'| 'default'| 'small' | — |
| type | control the type of buttons in this button-group | ^[enum]'primary'| 'success'| 'warning'| 'danger'| 'info' | — |
ButtonGroup Slots
| Name | Description | Subtags |
|---|---|---|
| default | customize button group content | Button |