Skip to content
On this page

组件库文档 tmui.design

按钮 Button

常用组件按钮。


🌶️ 按钮 Button 示例

查看模拟效果
示例代码
vue
<template>
    <tm-app>
        <tm-sheet :margin="[32,32,32,0]">
            <tm-text :font-size="24" _class="font-weight-b" label="基本示例"></tm-text>
            <tm-divider></tm-divider>
            <view class="flex flex-row flex-wrap">
                <tm-button :margin="[10]" :shadow="0"  size="large" label="按钮">
                </tm-button>
                <tm-button :margin="[10]" :shadow="0"  size="normal" label="按钮"></tm-button>
                <tm-button :margin="[10]" size="small" :shadow="0" label="按钮"></tm-button>
                <tm-button :margin="[10]" size="mini" :shadow="0" label="按钮"></tm-button>

				<tm-button :margin="[10]" :shadow="0" text size="normal" outlined label="浅边框"></tm-button>
                <tm-button :margin="[10]" :shadow="0" :border="6" outlined size="normal" label="深边框"></tm-button>
                <tm-button :margin="[10]" transprent text :shadow="0" size="normal" label="透明背景"></tm-button>
            </view>
            <tm-button block label="block"></tm-button>
        </tm-sheet>
        <tm-sheet>
            <tm-text :font-size="24" _class="font-weight-b" label="带图标"></tm-text>
            <tm-divider></tm-divider>
            <view class="flex flex-row flex-wrap">
                <tm-button  icon="tmicon-tongzhifill" size="normal" label="按钮"></tm-button>
                <tm-button color="red" icon="tmicon-account" :width="86" :round="10" :height="86" :fontSize="40"
                    :margin="[10]" :shadow="0" size="normal"></tm-button>
                <tm-button color="green" icon="tmicon-account" :width="86" :round="10" :height="86" :fontSize="40"
                    :margin="[10]" :shadow="0" text size="normal"></tm-button>
                <tm-button icon="tmicon-account" color="pink" :margin="[10]" :shadow="0" text :border="2"
                    borderStyle="dashed" size="normal" label="按钮"></tm-button>
            </view>
        </tm-sheet>
        <tm-sheet>
            <tm-text :font-size="24" _class="font-weight-b" label="带图标"></tm-text>
            <tm-divider></tm-divider>
            <view class="flex flex-row flex-wrap">
                <tm-button  :margin="[0]" disabled icon="tmicon-tongzhifill" size="normal" label="禁用"></tm-button>
                <tm-button :margin="[24,0]" loading icon="tmicon-tongzhifill" size="normal" label="加载中"></tm-button>
                <tm-button  :margin="[0,24]" icon="tmicon-tongzhifill" size="normal" label="正常"></tm-button>
            </view>
        </tm-sheet>
        <tm-sheet :margin="[32,0,32,32]">
            <tm-text :font-size="24" _class="font-weight-b" label="渐变样式,更多属性见文档"></tm-text>
			<tm-divider></tm-divider>
            <tm-button :linear-color="['#ea3c2d','#ff9d14']" color="orange" font-color="white" linear="left" block label="自定义渐变背景"></tm-button>
            <tm-button  linear="right" block label="light"></tm-button>
            <tm-button  linear="right" linearDeep="dark" block label="dark"></tm-button>
            <tm-button linear="right" linearDeep="accent" block label="accent"></tm-button>
        </tm-sheet>
    </tm-app>
</template>
<script lang="ts" setup>
import { ref } from "vue"
import { onShow, onLoad } from "@dcloudio/uni-app";
import { useTmpiniaStore } from "@/tmui/tool/lib/tmpinia";

import tmApp from "../../tmui/components/tm-app/tm-app.vue"
import tmSheet from "@/tmui/components/tm-sheet/tm-sheet.vue"
import tmText from "@/tmui/components/tm-text/tm-text.vue"
import tmButton from "../../tmui/components/tm-button/tm-button.vue"
import tmDivider from "../../tmui/components/tm-divider/tm-divider.vue"
import tmRow from "../../tmui/components/tm-row/tm-row.vue"
import tmCol from "../../tmui/components/tm-col/tm-col.vue"

const store = useTmpiniaStore();

// setTimeout(()=>{
//     if(typeof store.tmuiConfig.themeConfig?.component?.button?.round !='undefined'){
//         store.tmuiConfig.themeConfig.component.button.round = 24
//         console.log(store.tmuiConfig.themeConfig)
//     }
// },2000)

</script>

🌶️ 兼容性

APP-VUEAPP-NVUE小程序WEB/H5VUE3/TS
✔️✔️✔️✔️✔️

🌱 参数

本组件含有公共属性 公共属性

参数名类型默认值描述
transprentBooleanfalse是否透明
followThemeBooleantrue是否跟随全局主题
sizeString'normal'按钮尺寸:mini,small,normal,middle,large
fontSizeNumber0按钮文字大小,单位rpx
fontColorv3.0.63+String""按钮文字/图标主题色,默认为空,自动配色
marginArrayasPropType<Array<number>>()=>[0,16]外间距[x,y]x=左右,y=上下
paddingArrayasPropType<Array<number>>()=>[0,0]内间距[x,y]x=左右,y=上下
shadowNumber2投影,0-25
widthNumber0宽度,单位rpx
heightNumber0高度,单位rpx
blockBooleanfalse使用按钮宽度自动100%
roundNumber2圆角-1-25,单位rpx,如果想去除按钮圆角,请设置为-1
loadingBooleanfalse使按钮加载状态,其它事件不会触发
disabledBooleanfalse是否禁用
urlString''页面地址,当提供时,点击会跳转到相应页面
labelString''按钮文字
iconString''按钮图标
formTypeString''submit,reset,本组件额外新增:'filterCancel','filterConfirm',提供此值时,此按钮可以配合form组件用来提交事件表单
openTypeString''开放能力,见文档
appParameterString''见文档
sessionFromString''见文档
sendMessageTitleString''见文档
sendMessagePathString''见文档
sendMessageImgString''见文档
sendMessageCardString''见文档
roundNumber3圆角0-25,单位rpx
disabledColorStringgrey-1按钮被禁用时展现的颜色

🌹 事件

事件名参数返回数据描述
click
touchstart
touchmove
touchcancel
touchend
tap
longpress
getphonenumber
getuserInfo见文档
getUserProfile见文档
error
opensetting见文档
launchapp见文档
contact见文档

🌽 slot插槽

默认default,为文本内容。这个默认只有非nvue才有用。我不建议用默认插槽来书写按钮文本。原因是不能跨平台,建议使用按钮属性label

🥗 ref方法