Checkbox Checkbox
Toggle a standalone value or an option in a checkbox group.
Import
Use <hui-checkbox> 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-checkbox
v-model="checked"
label="同意条款 / Accept terms"
@update:model-value="event0"
@change="event1"
/>
<text>{{ checked }}</text>
<hui-checkbox indeterminate label="部分选中 / Mixed" /><hui-checkbox
disabled
:model-value="true"
label="禁用 / Disabled"
/><hui-checkbox readonly :model-value="true" label="只读 / Read only" />
<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 checked = ref<string | number | boolean>(false)
const event0 = (arg0: unknown) => {
lastEvent.value = 'update:modelValue' + ': ' + [describe(arg0)].join(', ')
}
const event1 = (arg0: unknown) => {
lastEvent.value = 'change' + ': ' + [describe(arg0)].join(', ')
}
</script>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue | ChoiceValue | undefined | Controlled value; undefined means omitted. |
trueValue | ChoiceValue | true | Value representing the checked state. |
falseValue | ChoiceValue | false | Value representing the unchecked state. |
value | ChoiceValue | undefined | Option value or displayed value. |
label | string | — | Visible label. |
indeterminate | boolean | false | Indeterminate checkbox state. |
disabled | boolean | false | Disable interaction. |
readonly | boolean | undefined | Read-only presentation without value changes. |
shape | "round" | "square" | — | Selection indicator shape. |
iconPosition | "left" | "right" | — | Icon position relative to the label. |
size | ComponentSize | — | Component size; inherits configuration when omitted. |
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 |
|---|---|---|
update:modelValue | (value: string | number | boolean) | Request a controlled value update. |
change | (value: string | number | boolean) | Emitted after the value changes. |
Slots
| Slot | Parameters | Description |
|---|---|---|
icon | { checked, indeterminate, disabled } | Custom icon region; replaces its fallback content. |
default | — | Main content. |
Methods
None.
Types
CheckboxProps、CheckboxValue、CheckboxEmits are available from @nscode/handy-uni.
ts
export type CheckboxValue = ChoiceValue
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 |
Follow the smoke checklist. Device evidence is tracked separately; unit tests do not establish device acceptance.