Skip to content

Button Component ​

This component is a secondary encapsulation built on top of uni-app's basic button component

📌 Platform Differences ​

APP(vue)H5WeChat Mini ProgramAlipay Mini Program
✔✔✔✔

⚠️ Notes ​

1. Click Event ​

Please use the @click event for button clicks, do not use @tap, as @tap is invalid in WeChat Mini Program:

html
<!-- Correct -->
<hy-button text="Click" @click="onClick"></hy-button>

<!-- Incorrect -->
<hy-button text="Click" @tap="onClick"></hy-button>

2. icon Property ​

The icon property accepts an icon configuration object:

html
<!-- Using a built-in icon -->
<hy-button text="Delete" :icon="{ name: IconConfig.DELETE }"></hy-button>

<!-- Using a custom icon -->
<hy-button text="Delete" :icon="{ name: 'delete', customPrefix: 'icon' }"></hy-button>

3. stop Event Bubbling ​

By default, stop is true, which prevents event bubbling. To allow bubbling, set stop="false":

html
<hy-button text="Allow bubbling" :stop="false" @click="onClick"></hy-button>

4. Throttling ​

You can set the button click throttle time via throttleTime to avoid repeated clicks:

html
<!-- Can only be clicked once within 3 seconds -->
<hy-button text="Submit" :throttle-time="3000" @click="onSubmit"></hy-button>

5. Open Capabilities ​

The component has integrated all open capabilities of the uni-app button component. Refer to the official documentation for usage:

html
<!-- Get user info -->
<hy-button open-type="getUserInfo" @getuserinfo="onGetUserInfo">Get Info</hy-button>

<!-- Get phone number -->
<hy-button open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">Get Phone Number</hy-button>

🏯 Basic Usage Examples ​

html
<template>
    <!-- Global usage -->
    <hy-button text="Basic Button"></hy-button>

    <!-- Using a slot -->
    <hy-button>Slot content</hy-button>
</template>

Setting Button Colors ​

html
<template>
    <hy-button type="info" text="Default Button"></hy-button>
    <hy-button type="success" text="Success Button"></hy-button>
    <hy-button type="primary" text="Primary Button"></hy-button>
    <hy-button type="error" text="Danger Button"></hy-button>
    <hy-button type="warning" text="Warning Button"></hy-button>

    <!-- Gradient button -->
    <hy-button text="Gradient" color="linear-gradient(to right, red, blue)"></hy-button>
</template>

Plain (Outlined) Buttons ​

html
<template>
    <hy-button type="info" text="Plain Button" plain></hy-button>
    <hy-button type="success" text="Plain Success" plain></hy-button>
    <hy-button type="primary" text="Plain Primary" plain></hy-button>
    <hy-button type="error" text="Plain Danger" plain></hy-button>
    <hy-button type="warning" text="Plain Warning" plain></hy-button>

    <!-- Gradient plain button -->
    <hy-button text="Gradient Plain" color="linear-gradient(to right, red, blue)" plain></hy-button>
</template>

Setting Button Icons ​

html
<template>
    <!-- Delete icon -->
    <hy-button type="error" text="Delete" :icon="{ name: IconConfig.DELETE }"></hy-button>

    <!-- Custom icon -->
    <hy-button
        type="error"
        text="Delete"
        plain
        :icon="{ name: 'delete', customPrefix: 'icon' }"
    ></hy-button>

    <!-- Loading button -->
    <hy-button type="success" text="Loading" loading></hy-button>

    <!-- Custom loading text -->
    <hy-button type="primary" loading loading-text="Submitting"></hy-button>
</template>

<script setup>
    import { IconConfig } from 'hy-app';
</script>

Button Shape ​

html
<template>
    <hy-button type="success" text="Square Button" shape="square"></hy-button>
    <hy-button type="success" text="Circle Button" shape="circle"></hy-button>
</template>

Button Size ​

html
<template>
    <hy-button type="success" text="Large Button" size="large"></hy-button>
    <hy-button type="success" text="Default Button" size="medium"></hy-button>
    <hy-button type="success" text="Small Button" size="small"></hy-button>
    <hy-button type="success" text="Mini Button" size="mini"></hy-button>
</template>

Setting Various Button States ​

html
<template>
    <!-- Hairline button -->
    <hy-button text="Hairline Button" :hairline="true"></hy-button>

    <!-- Borderless button -->
    <hy-button text="Borderless Button" :border="false"></hy-button>

    <!-- Disabled button -->
    <hy-button text="Disabled Button" :disabled="true"></hy-button>

    <!-- Disabled state (with loading) -->
    <hy-button text="Disabled" :disabled="true" loading></hy-button>
</template>

Throttle Control ​

html
<template>
    <!-- Can only be clicked once within 3 seconds -->
    <hy-button type="primary" text="Submit" :throttle-time="3000" @click="onSubmit"></hy-button>
</template>

<script setup>
    const onSubmit = () => {
        uni.showToast({
            title: 'Submitted successfully',
            icon: 'success',
        });
    };
</script>

Custom Styles ​

html
<template>
    <!-- Custom padding -->
    <hy-button text="Custom Style" :custom-style="{ padding: '20rpx 40rpx' }"></hy-button>

    <!-- Custom class name -->
    <hy-button text="Custom Class" custom-class="my-button"></hy-button>
</template>

<style lang="scss" scoped>
    :deep(.my-button) {
        border-radius: 10rpx;
        box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
    }
</style>

Open Capabilities ​

html
<template>
    <!-- Get user info -->
    <hy-button
        open-type="getUserInfo"
        type="primary"
        text="Get User Info"
        @getuserinfo="onGetUserInfo"
    ></hy-button>

    <!-- Get phone number -->
    <hy-button
        open-type="getPhoneNumber"
        type="primary"
        text="Get Phone Number"
        @getphonenumber="onGetPhoneNumber"
    ></hy-button>

    <!-- Open customer service -->
    <hy-button open-type="contact" text="Contact Support" @contact="onContact"></hy-button>

    <!-- Open settings -->
    <hy-button open-type="openSetting" text="Open Settings" @opensetting="onOpenSetting"></hy-button>
</template>

<script setup>
    const onGetUserInfo = (e) => {
        console.log('User info:', e);
    };

    const onGetPhoneNumber = (e) => {
        console.log('Phone number:', e);
    };

    const onContact = () => {
        console.log('Open customer service');
    };

    const onOpenSetting = () => {
        console.log('Open settings');
    };
</script>

Integration of Open Capabilities Across Mini Programs ​

Hy Component Library has integrated all open capabilities of the uni-app button component (as of 2025-04-14). Simply use them according to the uni-app documentation. If you find anything missing, please join our community group to report it.

API ​

Button Props ​

ParameterDescriptionTypeDefault
textButton textstring-
iconButton icon configuration, see Icon API for detailsHyIconProps-
colorButton color, supports linear-gradient valuesstring-
stopWhether to stop event bubblingbooleantrue
borderWhether to show the button borderbooleantrue
hairlineWhether to show the button's hairline borderbooleantrue
typeButton style typeerror|warning|success|primary|infoprimary
sizeButton sizesmall|medium|large|minimedium
shapeButton shape, see above for detailscircle|squaresquare
plainWhether the button is plain (outlined) with a transparent backgroundbooleanfalse
disabledWhether disabledbooleanfalse
loadingWhether the button is loadingbooleanfalse
loadingTextLoading prompt textstring-
loadingModeLoading icon typespinner|circle|semicirclespinner
loadingSizeLoading icon sizestring | number-
openTypeOpen capability, see the uni-app documentation on the button component for detailsstring-
scopeUsed in Alipay Mini Program, effective when open-type is getAuthorizephoneNumber|userInfo-
formTypeUsed for the <form> component; clicking triggers the submit/reset event of the <form> component respectivelystring-
appParameterParameters passed to the APP when opening it, effective when open-type=launchApp (Note: only effective in WeChat Mini Program and QQ Mini Program)string-
hoverStopPropagationSpecifies whether to prevent ancestor nodes of this node from showing the pressed state, effective in WeChat Mini Program (default true)booleantrue
langSpecifies the language of the returned user info: zh_CN Simplified Chinese, zh_TW Traditional Chinese, en Englishstringen
sessionFromSession source, effective when openType="contact"string-
sendMessageTitleIn-session message card title, effective when openType="contact"string-
sendMessagePathMini program path that the in-session message card navigates to when clicked, effective when openType="contact"string-
sendMessageImgIn-session message card image, effective when openType="contact"string-
showMessageCardWhether to display the in-session message card. When set to true, a "mini programs you may want to send" prompt appears in the lower-right corner after the user enters a customer service session; users can tap it to quickly send mini program messages, effective when openType="contact"booleanfalse
dataNameExtra parameter used for the mini program's data-xxx attribute, retrieved via target.dataset.namestring-
throttleTimeThrottle: can only be triggered once within a given period, in millisecondsnumber0
hoverStartTimeHow long after pressing before the pressed state appears, in millisecondsnumber0
hoverStayTimeHow long the pressed state remains after the finger is released, in millisecondsnumber200
customStyleCustom external styles to applyCSSProperties-
customClassCustom external class namestring-

Events ​

Event NameDescriptionCallback ParametersPlatform
clickButton click. Do not use the @tap event, as it is invalid in WeChat Mini Program. Returns the click event and its parametersevent-
getphonenumberEffective when open-type="getPhoneNumber"eventWeChat Mini Program, Alipay Mini Program
getuserinfoWhen the user taps this button, the retrieved user info is returned; the value obtained from the detail of the returned parameters is the same as uni.getUserInfoeventWeChat Mini Program, Alipay Mini Program
errorCallback fired when an error occurs while using an open capabilityeventWeChat Mini Program
opensettingCallback fired after the authorization settings page is opened and closedeventWeChat Mini Program
launchappCallback fired when opening an APP succeedseventWeChat Mini Program
agreeprivacyauthorizationCallback for the user agreeing to the privacy policy, effective when open-type="agreePrivacyAuthorization"eventWeChat Mini Program
chooseavatarCallback for retrieving the user's avatareventWeChat Mini Program
contactCustomer service message callbackeventWeChat Mini Program

Slots ​

Slot NameDescriptionAccepted Value
defaultDefault slot-

CSS Variables ​

Variable NameDescriptionDefault ValueNotes
--hy-button-height-largelarge height50pxThe medium size follows this value
--hy-button-height-mediumDefault size height40px
--hy-button-height-smallsmall height30px
--hy-button-height-minimini height22px
--hy-button-font-size-largelarge font size20pxWhen the text-size prop is set, the prop takes precedence
--hy-button-font-size-mediummedium font size15pxSame as above
--hy-button-font-size-smallsmall font size12pxSame as above
--hy-button-font-size-minimini font size10pxSame as above
--hy-button-padding-largelarge padding0 15px
--hy-button-padding-mediummedium padding0 12px
--hy-button-padding-smallsmall padding0 8px
--hy-button-padding-minimini padding0 8px
--hy-button-min-width-smallsmall min width60pxEffective for non-APP-NVUE
--hy-button-min-width-minimini min width50pxEffective for non-APP-NVUE
--hy-button-radiusSquare button border radius (shape=square)Follows --hy-radius-sm (8rpx)For circle buttons, override --hy-radius-semicircle
--hy-button-disabled-opacityDisabled opacity0.5
--hy-button-hairline-widthHairline border width (hairline)0.5px
12:33
battery