Skip to content

Button 按钮

介绍

按钮用于触发一个操作,如提交表单。

导入

js
import Button from '@/components/basic/Button.vue'

用法

基础用法

按钮支持 default、primary、success、warning、danger 五种类型,默认为 default。

vue
<template>
  <FlexRow wrap :padding="10" :gap="10">
    <Button text="primary" type="primary" />
    <Button text="success" type="success" />
    <Button text="default" type="default" />
    <Button text="danger" type="danger" />
    <Button text="warning" type="warning" />
  </FlexRow>
</template>

关于他们的主题颜色修改,可参考 主题与颜色

朴素按钮

通过 plain 属性将按钮设置为朴素按钮,朴素按钮的文字为按钮颜色,背景为白色。

vue
<template>
  <FlexRow wrap :padding="10" :gap="10">
    <Button plain text="primary" type="primary" />
    <Button plain text="success" type="success" />
    <Button plain text="default" type="default" />
    <Button plain text="danger" type="danger" />
    <Button plain text="warning" type="warning" />
  </FlexRow>
</template>

禁用状态

通过 touchable=false 属性来禁用按钮,禁用状态下按钮不可点击。

也可不提供 onPress 函数,此时按钮也无法响应点击。

vue
<template>
  <FlexRow wrap :padding="10" :gap="10">
    <Button touchable="false" text="primary" type="primary" />
    <Button touchable="false" text="success" type="success" />
    <Button touchable="false" text="default" type="default" />
  </FlexRow>
</template>

自定义颜色

vue
<template>
  <FlexRow wrap :padding="10" :gap="10">
    <Button text="自定义颜色" type="custom" color="#f00" pressedColor="#ff0" textColor="#fff" />
  </FlexRow>
</template>

加载状态

vue
<template>
  <FlexRow wrap :padding="10" :gap="10">
    <Button loading="true" type="primary" icon="top-filling" />
    <Button loading="true" loadingText="加载中" type="success" />
  </FlexRow>
</template>

按钮形状

通过 square 设置方形按钮,通过 round 设置圆形按钮。

vue
<template>
  <FlexRow wrap :padding="10" :gap="10">
    <Button shape="square" text="方形按钮" type="primary" />
    <Button shape="round" text="圆形按钮" type="success" />
    <Button shape="round" radius="5" text="可以通过raduis设置圆角大小" type="primary" />
  </FlexRow>
</template>

图标

通过 icon 属性设置按钮图标,支持 Icon 组件里的所有图标,也可以传入图标 URL。

vue
<template>
  <FlexRow wrap :padding="10" :gap="10">
    <Button icon="top-filling" type="primary" />
    <Button icon="http://test.com/images/test.png" text="按钮" type="primary" />
    <Button icon="download" plain text="按钮" type="success" />
  </FlexRow>
</template>

按扭尺寸

支持 large、normal、small、mini 四种尺寸,默认为 normal。

vue
<template>
  <FlexRow wrap center :padding="10" :gap="10">
    <Button text="大号按钮" type="primary" size="large" />
    <Button text="普通按钮" type="primary" size="medium" />
    <Button text="小型按钮" type="primary" size="small" />
    <Button text="迷你按钮" type="primary" size="mini" />
  </FlexRow>
</template>

API 参考

Button

按钮组件。

Props

名称说明类型必填默认值
text按钮文字string--
type按钮支持 default、primary、success、warning、danger、custom 自定义 六种类型ButtomType-'default'
block占满父级主轴boolean-false
plain通过 plain 属性将按钮设置为朴素按钮,朴素按钮的文字为按钮颜色,背景为白色。boolean-false
loading通过 loading 属性设置按钮为加载状态,加载状态下默认会隐藏按钮文字,可以通过 loadingText 设置加载状态下的文字。boolean-false
loadingText加载状态下的文字。string-false
loadingColor加载状态圆圈颜色string--
shape按钮形状 通过 square 设置方形按钮,通过 round 设置圆形按钮。"square" ︱ "round"-'round'
icon左侧图标。支持 Icon 组件里的所有图标,也可以传入图标的图片 URL(http/https)。string--
iconProps当使用图标时,左侧图标的附加属性IconProps--
rightIcon右侧图标。支持 Icon 组件里的所有图标,也可以传入图标的图片 URL(http/https)。string--
rightIconProps当使用图标时,右侧图标的附加属性IconProps--
touchable是否可以点击boolean-true
radius当按扭为round圆形按扭时的圆角大小。number-5
size按钮尺寸. 支持 large、medium、small、mini 四种尺寸。ButtomSizeType-'medium'
color通过 color 属性可以自定义按钮的背景颜色,仅在 type 为 custom 时有效string-grey
textColor按钮文字的颜色。string--
pressedTextColor按下时按钮文字的颜色。string--
textStyle按钮文字的样式。TextStyle--
pressedColor按下时的颜色,仅在 type 为 custom 时有效string-pressed.primary
disabledColor禁用时的颜色,仅在 type 为 custom 时有效string-grey
padding强制控制按钮的边距; 如果是数字,则设置所有方向边距; 两位数组 [vetical,horizontal]; 四位数组 [top,right,down,left]number | number[]--
viewProps外层容器参数FlexProps--
innerStyle自定义样式ViewStyle--

Slots

名称说明
default按钮的文字,等同于 text 属性
leftIcon左侧图标插槽
rightIcon右侧图标插槽

Events

名称说明参数
click点击事件$event

主题变量

名称类型默认值说明
ButtonBorderWidthnumber1.5-
ButtonDangerBackgroundColorstringdanger-
ButtonDangerColorstringwhite-
ButtonDisableOpacitynumber0.5-
ButtonLargeFonstSizenumber20-
ButtonLargerFonstSizenumber28-
ButtonMediumFonstSizenumber14-
ButtonMiniFonstSizenumber10.5-
ButtonPaddingHorizontalLargenumber20-
ButtonPaddingHorizontalLargernumber30-
ButtonPaddingHorizontalMediumnumber15-
ButtonPaddingHorizontalMininumber0-
ButtonPaddingHorizontalSmallnumber10-
ButtonPaddingVerticalLargenumber15-
ButtonPaddingVerticalLargernumber20-
ButtonPaddingVerticalMediumnumber10-
ButtonPaddingVerticalMininumber0-
ButtonPaddingVerticalSmallnumber5-
ButtonPlainDangerBorderColorstringdanger-
ButtonPlainDangerColorstringdanger-
ButtonPlainDefaultBorderColorstringborder-
ButtonPlainDefaultColorstringtext-
ButtonPlainPrimaryBorderColorstringprimary-
ButtonPlainPrimaryColorstringprimary-
ButtonPlainSuccessBorderColorstringsuccess-
ButtonPlainSuccessColorstringsuccess-
ButtonPlainWarningBorderColorstringwarning-
ButtonPlainWarningColorstringwarning-
ButtonPrimaryBackgroundColorstringprimary-
ButtonPrimaryColorstringwhite-
ButtonSmallFonstSizenumber12-
ButtonSuccessBackgroundColorstringsuccess-
ButtonSuccessColorstringwhite-
ButtonWarningBackgroundColorstringwarning-
ButtonWarningColorstringwhite-