Skip to content

Button 按钮

按钮用于触发一个操作或行为,支持多种样式、尺寸和状态。

基础用法

最简单的按钮形式,可以设置不同颜色、形状、尺寸等属性。

vue
<template>
  <u-button>默认按钮</u-button>
  <u-button color="primary">主要按钮</u-button>
  <u-button color="success">成功按钮</u-button>
  <u-button color="warning">警告按钮</u-button>
  <u-button color="error">错误按钮</u-button>
</template>

不同样式

按钮支持不同的变体样式,包括填充、描边、文本、调性等。

vue
<template>
  <u-button variant="contained">填充按钮</u-button>
  <u-button variant="outlined">描边按钮</u-button>
  <u-button variant="text">文本按钮</u-button>
  <u-button variant="tonal">调性按钮</u-button>
</template>

不同尺寸

按钮有四种尺寸:迷你([mini](file:///d:\github\ume-ui\packages\ume-ui\button\src\types.ts#L3-L3))、小号([small](file:///d:\github\ume-ui\packages\ume-ui\button\src\types.ts#L9-L9))、中号([medium](file:///d:\github\ume-ui\packages\ume-ui\button\src\types.ts#L10-L10))、大号([large](file:///d:\github\ume-ui\packages\ume-ui\button\src\types.ts#L11-L11))。

vue
<template>
  <u-button size="mini">迷你按钮</u-button>
  <u-button size="small">小号按钮</u-button>
  <u-button size="medium">中号按钮</u-button>
  <u-button size="large">大号按钮</u-button>
</template>

不同形状

按钮支持圆形和圆角两种特殊形状。

vue
<template>
  <u-button shape="round">圆角按钮</u-button>
  <u-button shape="circle">圆</u-button>
  <u-button shape="circle" icon>
    <i>+</i>
  </u-button>
</template>

禁用状态

通过 [disabled](file:///d:\github\ume-ui\packages\ume-ui\button\src\types.ts#L4-L4) 属性禁用按钮。

vue
<template>
  <u-button disabled>禁用按钮</u-button>
  <u-button color="primary" disabled>禁用按钮</u-button>
</template>

加载状态

通过 [loading](file:///d:\github\ume-ui\packages\ume-ui\button\src\types.ts#L5-L5) 属性显示加载状态。

vue
<template>
  <u-button loading>加载中...</u-button>
  <u-button color="primary" loading>加载中...</u-button>
</template>

自定义尺寸

可以通过 [width](file:///d:\github\ume-ui\packages\ume-ui\button\src\types.ts#L8-L8) 和 [height](file:///d:\github\ume-ui\packages\ume-ui\button\src\types.ts#L7-L7) 属性自定义按钮尺寸。

vue
<template>
  <u-button width="120px" height="60px">自定义尺寸</u-button>
</template>

API

属性说明类型默认值
color按钮颜色default | primary | success | warning | errordefault
variant按钮变体contained | outlined | text | tonalcontained
size按钮尺寸mini | small | medium | largemedium
shape按钮形状default | round | circledefault
disabled是否禁用booleanfalse
loading是否加载中booleanfalse
width自定义宽度string-
height自定义高度string-
icon是否图标模式booleanfalse