Button Button
Trigger actions with semantic colors, variants and loading feedback.
Import
Use <hui-button> with uni-app easycom. Import public types from @nscode/handy-uni. For ordinary Vue 3, install the preview plugin from @nscode/handy-uni/web and register its components.
Examples
Interact with the controls to see values and event results on the page.
vue
<template>
<view>
<hui-button
type="primary"
@click="event0"
@getphonenumber="event1"
@getuserinfo="event2"
@chooseavatar="event3"
@opensetting="event4"
@launchapp="event5"
@contact="event6"
@error="event7"
>保存 / Save</hui-button
>
<hui-button v-for="type in types" :key="type" :type="type">{{ type }}</hui-button
><hui-button v-for="variant in variants" :key="variant" :variant="variant">{{
variant
}}</hui-button
><hui-button v-for="size in sizes" :key="size" :size="size">{{ size }}</hui-button
><hui-button loading loading-text="保存中 / Saving" /><hui-button disabled
>禁用 / Disabled</hui-button
><hui-button block round>整行圆角 / Rounded block</hui-button>
<text>{{ lastEvent }}</text>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('No event yet')
const describe = (value: unknown) => {
try {
return JSON.stringify(value) ?? String(value)
} catch {
return String(value)
}
}
const types = ['default', 'primary', 'success', 'warning', 'danger', 'info'] as const
const variants = ['solid', 'plain', 'outline', 'text'] as const
const sizes = ['large', 'default', 'small'] as const
const event0 = (arg0: unknown) => {
lastEvent.value = 'click' + ': ' + [describe(arg0)].join(', ')
}
const event1 = (arg0: unknown) => {
lastEvent.value = 'getphonenumber' + ': ' + [describe(arg0)].join(', ')
}
const event2 = (arg0: unknown) => {
lastEvent.value = 'getuserinfo' + ': ' + [describe(arg0)].join(', ')
}
const event3 = (arg0: unknown) => {
lastEvent.value = 'chooseavatar' + ': ' + [describe(arg0)].join(', ')
}
const event4 = (arg0: unknown) => {
lastEvent.value = 'opensetting' + ': ' + [describe(arg0)].join(', ')
}
const event5 = (arg0: unknown) => {
lastEvent.value = 'launchapp' + ': ' + [describe(arg0)].join(', ')
}
const event6 = (arg0: unknown) => {
lastEvent.value = 'contact' + ': ' + [describe(arg0)].join(', ')
}
const event7 = (arg0: unknown) => {
lastEvent.value = 'error' + ': ' + [describe(arg0)].join(', ')
}
</script>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
type | ButtonType | 'default' | Semantic type or input mode; see the type definition. |
variant | ButtonVariant | 'solid' | Solid, plain, outlined or text button appearance. |
size | ComponentSize | — | Component size; inherits configuration when omitted. |
block | boolean | undefined | Make the button fill its row. |
round | boolean | undefined | Use rounded or pill styling. |
icon | string | — | Registered icon name. |
iconPosition | "left" | "right" | 'left' | Icon position relative to the label. |
disabled | boolean | false | Disable interaction. |
loading | boolean | false | Loading state. |
loadingText | string | — | Text displayed while loading. |
openType | string | — | WeChat native button open capability. |
formType | "submit" | "reset" | — | Native form submit or reset behavior. |
ariaLabel | string | — | Accessible name. |
ariaDisabled | boolean | false | Sets aria-disabled only; does not block clicks or set native disabled. Application logic controls interaction. |
Root attributes: common props. A Boolean default of undefined supports inheritance; explicit false overrides it. Other Boolean props default to false unless listed otherwise.
Events
| Event | Parameters | Description |
|---|---|---|
click | (event: unknown) | Emitted when the interactive area is clicked. |
getphonenumber | (event: unknown) | Reports the corresponding interaction result. |
getuserinfo | (event: unknown) | Reports the corresponding interaction result. |
chooseavatar | (event: unknown) | Reports the corresponding interaction result. |
opensetting | (event: unknown) | Reports the corresponding interaction result. |
launchapp | (event: unknown) | Reports the corresponding interaction result. |
contact | (event: unknown) | Reports the corresponding interaction result. |
error | (event: unknown) | Reports the corresponding interaction result. |
Slots
| Slot | Parameters | Description |
|---|---|---|
icon | — | Custom icon region; replaces its fallback content. |
default | — | Main content. |
Methods
None.
Types
ButtonProps、ButtonType、ButtonVariant、ButtonEmits are available from @nscode/handy-uni.
ts
export type ButtonType = 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info'
export type ButtonVariant = 'solid' | 'plain' | 'outline' | 'text'
Platform notes
| Behavior | uni-app H5 | WeChat Mini Program | App-vue | Ordinary Vue 3 Web (preview) |
|---|---|---|---|---|
| Basic interaction | Supported; device checks pending | Supported; device checks pending | Supported; device checks pending | Supported by the web platform adapter |
| Open capabilities | No Mini Program capabilities | Native button handles openType and callbacks | Depends on native host capabilities | openType is ignored with a warning; formType maps to HTML type |
Follow the smoke checklist. Device evidence is tracked separately; unit tests do not establish device acceptance.