Skip to content
本页目录

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

NameDescriptionTypeDefault
sizebutton size^[enum]'large'| 'default'| 'small'—
typebutton type^[enum]'primary'| 'success'| 'warning'| 'danger'| 'info'| 'text'(delete)—
plaindetermine whether it's a plain button^[boolean]false
textdetermine whether it's a text button^[boolean]false
bgdetermine whether the text button background color is always on^[boolean]false
linkdetermine whether it's a link button^[boolean]false
rounddetermine whether it's a round button^[boolean]false
circledetermine whether it's a circle button^[boolean]false
loadingdetermine whether it's loading^[boolean]false
loading-iconcustomize loading icon component^[string] / ^[Component]Loading
disableddisable the button^[boolean]false
iconicon component^[string] / ^[Component]—
autofocussame as native button's autofocus^[boolean]false
native-typesame as native button's type^[enum]'button'| 'submit'| 'reset'button
auto-insert-spaceautomatically insert a space between two chinese characters^[boolean]—
colorcustom button color, automatically calculate hover and active color^[string]—
darkdark mode, which automatically converts color to dark mode colors^[boolean]false

Button Slots

NameDescription
defaultcustomize default content
loadingcustomize loading component
iconcustomize icon component

Button Exposes

NameDescriptionType
refbutton html element^[object]Ref<HTMLButtonElement>
sizebutton size^[object]ComputedRef<'' | 'small' | 'default' | 'large'>
typebutton type^[object]ComputedRef<'' | 'default' | 'primary' | 'success' | 'warning' | 'info' | 'danger' | 'text'>
disabledbutton disabled^[object]ComputedRef<boolean>
shouldAddSpacewhether adding space^[object]ComputedRef<boolean>

ButtonGroup API

ButtonGroup Attributes

NameDescriptionTypeDefault
sizecontrol the size of buttons in this button-group^[enum]'large'| 'default'| 'small'—
typecontrol the type of buttons in this button-group^[enum]'primary'| 'success'| 'warning'| 'danger'| 'info'—

ButtonGroup Slots

NameDescriptionSubtags
defaultcustomize button group contentButton