Skip to content
# t-button

Button 按钮

t-button 组件介绍 ​

t-button 按钮组件,封装了常用的按钮样式和行为。支持多种类型(主要、次要、危险等)、尺寸,并能响应点击事件。支持小程序开放能力、表单提交等功能。

t-button 平台兼容 ​

HarmonyH5AndroidiOS小程序UTS
✅✅✅✅✅✅

t-button 基础用法 ​

基础用法参考 demo/button/button.uvue,通过 type 属性设置主题,使用 size 属性设置尺寸。

vue
<template>
	<view>
		<tui-theme-switch></tui-theme-switch>
		<introduction title="主题">
			<t-button class="mb-15"
					  type="primary">主要</t-button>
			<t-button class="mb-15"
					  type="info">信息</t-button>
			<t-button class="mb-15"
					  type="warning"
					  @click="test1">警告</t-button>
			<t-button class="mb-15"
					  type="error">危险</t-button>
		</introduction>
		<introduction title="主题+size">
			<view class="fais">
				<t-button class="mb-15 w-128"
						  type="primary"
						  :loading="true"
						  size="large">大</t-button>
				<t-button class="mb-15 w-98"
						  type="success"
						  size="medium">正常</t-button>
				<t-button class="mb-15 w-60"
						  type="info"
						  size="small">小</t-button>
				<t-button class="mb-15 w-46"
						  type="warning"
						  size="mini">迷你</t-button>
			</view>
		</introduction>
		<introduction title="定制">
			<view class="fl fjcb plr-15">
				<t-button class="twhr-40!"
						  left-icon-box-class="w-0!"
						  right-icon-class="s-23!"
						  right-icon="server-fill"
						  type="primary"></t-button>
				<t-button class="twhr-40!"
						  left-icon-box-class="w-0!"
						  right-icon="checkbox-mark"
						  type="success"></t-button>
				<t-button class="twhr-40!"
						  left-icon-box-class="w-0!"
						  right-icon-class="s-23!"
						  right-icon="star"
						  type="warning"></t-button>
				<t-button class="twhr-40!"
						  left-icon-box-class="w-0!"
						  right-icon-class="s-23!"
						  right-icon="trash"
						  type="error"></t-button>
			</view>
		</introduction>
		<introduction title="自定义样式覆盖主题">
			<t-button class="mb-15 bg-#0AB99C"
					  text-class="c-#fff">覆盖背景</t-button>
			<t-button class="mb-15 r-90 ptb-15 bil-#ff667f,#fdb247"
					  text-class="c-#fff">镂空覆盖测试</t-button>
			<t-button class="mb-15 r-90 ptb-15 bil-#a531dc,#4300b1"
					  text-class="c-#fff">镂空覆盖测试</t-button>
		</introduction>
		<introduction title="简易跳转功能">
			<t-button type="primary"
					  path="/demo/index/index">跳转</t-button>
		</introduction>
		<introduction title="防抖-节流">
			<t-button type="primary"
					  class="mb-15"
					  @click="test1"
					  :tdTime="1000"
					  :debounce="true">防抖(在1000ms内,只有最后一次操作)</t-button>
			<t-button type="primary"
					  @click="test1"
					  :tdTime="1000"
					  :throttle="true">节流(在1000ms内,只能触发一次)</t-button>
		</introduction>
	</view>
</template>

<script setup>
	const loading = ref(true)
	const disabled = ref(true)
	function test1() {
		console.log('test')
	}
	function test() {
		loading.value = !loading.value
	}
</script>

t-button Props ​

属性名说明类型默认值
size组件尺寸,可选 large、medium、small、ministring'medium'
type组件主题类型,可选 info、primary、error、warning、successstring''
disabled是否禁用booleanfalse
effect组件显示主题,可选 normal、dark、light、plainstring'normal'
hover是否启用点击效果booleantrue
path点击组件后跳转的页面路径;为空时仅响应事件string''
leftIcon左侧图标,支持图标名称或图片地址string''
rightIcon右侧图标,支持图标名称或图片地址string''
loading是否显示加载状态booleanfalse
loadingIcon加载状态的图标名称string'moments'
color字体、图标颜色string''
text是否为文本按钮样式booleanfalse
rounded是否为圆角按钮booleanfalse
hoverStopPropagation是否阻止点击态冒泡booleanfalse
hoverStartTime按住后多久出现点击态,单位毫秒number20
hoverStayTime手指松开后点击态保留时间,单位毫秒number70
pt样式穿透属性,用于自定义组件内部样式UTSJSONObject{}
native是否使用原生 button 标签booleanfalse
formType表单提交类型,可选 submit、resetstring''
openType小程序开放能力string''
lang指定返回用户信息的语言string''
sessionFrom会话来源string''
sendMessageTitle发送消息卡片标题string''
sendMessagePath发送消息卡片路径string''
sendMessageImg发送消息卡片图片string''
showMessageCard显示会话内消息卡片booleanfalse
appParameter打开 APP 时向 APP 传递的参数string''
groupId打开群聊卡片的群号string''
guildId打开频道卡片的频道号string''
publicId打开公众号卡片的公众号 IDstring''
phoneNumberNoQuotaToast无额度提示booleanfalse
createliveactivity创建直播间活动string''

size 说明 ​

  • large:大尺寸,按钮的尺寸较大,适用于需要强调操作或易于点击的区域
  • medium:中尺寸,按钮的尺寸适中,可能是默认尺寸,适用于大多数场景
  • small:小尺寸,按钮的尺寸较小,适用于空间有限或操作不是特别重要的区域
  • mini:迷你,按钮的尺寸最小,适用于紧凑布局或辅助操作

type 说明 ​

  • info:信息提示场景,通常用于提供一般的通知信息
  • primary:主要操作场景,用于强调某些主要的操作或信息
  • error:错误提示场景,用于指示出现了错误或问题
  • warning:警告提示场景,用于提示用户关于潜在的问题
  • success:成功提示场景,用于指示一个操作或过程已经成功完成

effect 说明 ​

  • normal:正常主题
  • dark:深色主题
  • light:浅色主题
  • plain:镂空主题

t-button Events ​

事件名说明回调参数
click点击时触发UniPointerEvent
transitionend动画结束时触发-
initFinished组件初始化完成时触发,返回组件节点信息NodeInfo
touchstart触摸开始时触发-
touchend触摸结束时触发-
touchmove触摸移动时触发-
touchcancel触摸取消时触发-
getuserinfo获取用户信息-
contact客服消息-
getphonenumber获取用户手机号-
error错误事件-
opensetting打开设置-
launchapp打开 APP-
chooseavatar选择头像-
chooseaddress选择地址-
chooseinvoicetitle选择发票抬头-
addgroupapp添加群应用-
subscribe订阅消息-
login登录-
getrealtimephonenumber获取实时手机号-
agreeprivacyauthorization同意隐私协议-

t-button Slots ​

插槽名说明
default默认插槽,用于设置按钮内容