TUI

0.3.7
Button 按钮​

用于触发操作的通用按钮组件,支持多种状态、图标与交互样式。

为了满足按钮的更直观的样式效果, medium 使用的是 12px 的字体,与其他组件medium的尺寸使用的是 14px 的字体不同。

可以通过--ts-button-font-size: var(--ts-font-size); 设置为标准大小字体。

基础用法
支持多种类型(type)与样式的按钮,包括默认、文本、成功、危险等,用于满足不同语义的交互需求。
示例代码
vue
<template>
 <TsButton>default 按钮</TsButton>
 <TsButton type="primary">基础按钮</TsButton>
 <TsButton type="warning">警告按钮</TsButton>
 <TsButton type="danger">危险按钮</TsButton>
 <TsButton type="success">成功按钮</TsButton>
 <TsButton type="text">文本按钮</TsButton>
</template>
loading、disabled、flash 效果
展示按钮的加载中状态和禁用状态,适用于异步请求或不可操作的场景。
示例代码
vue
<template>
  <TsButton :disabled="true">普通禁用</TsButton>
  <TsButton :disabled="true" :loading="true">提交订单</TsButton>
  <TsButton :disabled="true" :flash="true">欢迎登录</TsButton>
</template>
按钮尺寸
通过 size 属性可设置按钮的尺寸,支持 small、 medium 、 large 、x-large 四种预设值。 若不传入 size ,则默认使用 medium 尺寸。
示例代码
vue
<template>
  <div class="item-flex-center-wrap">
    <TsButton size="small">small</TsButton>
    <TsButton>medium</TsButton>
    <TsButton size="larage">larage</TsButton>
    <TsButton size="x-large">x-large</TsButton>
  </div>
</template>
border、icon、status的用法
支持状态图标(如 loading、success 等)与插槽自定义 icon,用于更丰富的按钮展示效果;还支持 `border` 描边样式和 `shadow` 阴影样式。
示例代码
vue
<template>
  <TsButton border type="default">border 效果</TsButton>
  <TsButton shadow>shadow按钮</TsButton>
  <TsButton status="sign">登录</TsButton>
  <TsButton status="verifying">安全环境检测</TsButton>
  <TsButton status="loading">上传中</TsButton>
  <TsButton status="success">保存成功</TsButton>
  <TsButton>
    <template #loading>
      <TsLoading></TsLoading>
    </template>
    <span>自定义ICON</span>
  </TsButton>
  <TsButton status="sign" :loading="loadingStatus" @click="handleLoading">点击开启loading</TsButton>
  <TsButton status="verifying" :loading="true">安全环境检测</TsButton>
  <TsButton status="loading" :loading="true">上传中</TsButton>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  const loadingStatus = ref(false);
  const handleLoading = () => {
    loadingStatus.value = true;
    setTimeout(() => {
      loadingStatus.value = false;
    }, 2000);
  };
</script>
shadow、color、 bg、hoverBg、borderColor 的用法
本示例展示了按钮组件的几个常用样式属性用法: bg 设置按钮背景色或渐变色,hoverBg 设置悬浮时背景色, color 设置文字颜色,borderColor 设置边框颜色(需开启 border), shadow 可开启默认阴影或自定义阴影效果。 这些属性组合使用,可灵活调整按钮外观和交互状态。
示例代码
vue
<template>
  <div class="item-flex-wrap">
    <TsButton bg="#2d5bff" hoverBg="#1e40af">快速开始</TsButton>
    <TsButton border bg="transparent" color="#2d5bff" borderColor="#2d5bff" hoverBg="#eff6ff">查看文档</TsButton>
    <TsButton shadow bg="linear-gradient(135deg, #6c5ce7, #9b59b6)" hoverBg="linear-gradient(135deg, #6c5ce7, #9b59b6)" color="#fff">查看文档</TsButton>
    <TsButton shadow="0 8px 25px rgba(108, 92, 231, 0.3)" bg="linear-gradient(135deg, #6c5ce7, #9b59b6)" hoverBg="linear-gradient(135deg, #6c5ce7, #9b59b6)" color="#fff">查看文档</TsButton>
  </div>
</template>
属性
属性名
说明
类型
可选值
默认值
type
按钮类型
String
primary / success / warning / danger / default / text
primary
disabled
是否禁用
Boolean
-
false
loading
是否加载中
Boolean
-
false
status
状态图标/状态标识(统一控制 icon 和语义)
String
sign/verifying/loading/success
round
是否圆角
Boolean
-
true
flash
是否闪烁
Boolean
-
false
size
按钮尺寸
String
large / medium / small / mini
medium
shadow
是否阴影
Boolean
-
false
border
是否边框
Boolean
-
false
color
按钮文字颜色
String
-
bg
按钮背景色
description
-
hoverBg
按钮背景色(悬浮)
String
-
borderColor
按钮border颜色
String
-
Slots
插槽名
说明
icon
自定义 icon 插槽, 不受loading状态影响
loading
自定义 loading 图标插槽