Skip to content

Button 按钮

常用的操作按钮。

基础用法

使用 typeplainroundcircle来定义按钮的样式。

<template>
  <p>
    <c-button>Default</c-button>
    <c-button type="primary">Primary</c-button>
    <c-button type="success">Success</c-button>
    <c-button type="info">Info</c-button>
    <c-button type="warning">Warning</c-button>
    <c-button type="danger">Danger</c-button>
  </p>

  <p>
    <c-button plain>Plain</c-button>
    <c-button type="primary" plain>Primary</c-button>
    <c-button type="success" plain>Success</c-button>
    <c-button type="info" plain>Info</c-button>
    <c-button type="warning" plain>Warning</c-button>
    <c-button type="danger" plain>Danger</c-button>
  </p>

  <p>
    <c-button round>Round</c-button>
    <c-button type="primary" round>Primary</c-button>
    <c-button type="success" round>Success</c-button>
    <c-button type="info" round>Info</c-button>
    <c-button type="warning" round>Warning</c-button>
    <c-button type="danger" round>Danger</c-button>
  </p>

  <p>
    <c-button icon="search" circle />
    <c-button type="primary" icon="edit" circle />
    <c-button type="success" icon="check" circle />
    <c-button type="info" icon="message" circle />
    <c-button type="warning" icon="star" circle />
    <c-button type="danger" icon="trash" circle />
  </p>
</template>

禁用状态

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

图标按钮

使用 icon属性来定义按钮的图标。

按钮组

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

按钮尺寸

使用 size属性来定义按钮的尺寸。

Tag

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

节流模式

可以通过 useThrottle 属性来定义按钮是否使用节流模式 默认为 true。

Button API

Props

NameDescriptionTypeDefault
size尺寸enum - 'large'| 'default'| 'small'
type类型enum - 'primary'| 'success'| 'warning'| 'danger'| 'info'info
plain是否为朴素按钮booleanfalse
round是否为圆角按钮booleanfalse
circle是否为圆形按钮booleanfalse
disabled按钮是否为禁用状态booleanfalse
icon按钮图标string-
autofocus是否自动聚焦(原生autofocus属性)booleanfalse
native-type原生 type 属性enum - 'button'| 'submit'| 'reset'button
tag自定义元素标签string/Componentbutton
use-throttle是否使用节流模式booleantrue
throttle-duration节流模式下,节流时间间隔(ms)number500

Events

NameDescriptionType
click按钮点击事件(event: MouseEvent)=> void

Slots

NameDescription
default默认插槽, 按钮内容

Expose

NameDescriptionType
ref按钮 html 元素Ref<HTMLButtonElement>
size按钮尺寸ComputedRef<''|'small' |'large'>
type按钮类型ComputedRef<''|'primary' |...>
disabled按钮禁用状态ComputedRef<boolean>

ButtonGroup API

Props

NameDescriptionTypeDefault
size尺寸enum - 'large'| 'default'| 'small'
type类型enum - 'primary'| 'success'| 'warning'| 'danger'| 'info'info
disabled按钮组是否为禁用状态booleanfalse

Slots

NameDescriptionSub Component
default默认插槽Button