Skip to content

Checkbox (多选-复选框)

选择多个选项。组件支持自定义样式、状态和事件自定义图标,适用于各种表单场景,提升用户体验和操作便捷性。

支持平台

安卓ios鸿蒙web微信小程序

示例代码

html
<template>
	<t-page main-class="p-30">
		<t-section title="主题-type-开启动画" main-class="mb-30"></t-section>
		<t-row main-class="mb-30 fww tdb tdr">
			<t-checkbox :transition="true">石榴</t-checkbox>
			<t-checkbox type="primary" icon="thumb-up" active-icon-class="ats-0.5" :transition="true">橙子</t-checkbox>
			<t-checkbox type="error" :transition="true">橙子</t-checkbox>
			<t-checkbox type="warning" :transition="true">梨子</t-checkbox>
		</t-row>
		<t-section title="size-large" main-class="mb-30 fww"></t-section>
		<t-row main-class="mb-30 fww tdb tdr">
			<t-checkbox :checked="true" type="p" size="large">石榴</t-checkbox>
			<t-checkbox type="p" size="large">橙子</t-checkbox>
			<t-checkbox type="p" size="large">香蕉</t-checkbox>
			<t-checkbox type="p" size="large">橙子</t-checkbox>
		</t-row>
		<t-section title="size-medium" main-class="mb-30 fww"></t-section>
		<t-row main-class="mb-30 fww tdb tdr">
			<t-checkbox type="p" size="medium">石榴</t-checkbox>
			<t-checkbox type="p" size="medium">橙子</t-checkbox>
			<t-checkbox type="p" size="medium">香蕉</t-checkbox>
			<t-checkbox type="p" size="medium" :disabled="true">橙子</t-checkbox>
		</t-row>
		<t-section title="size-small" main-class="mb-30 fww"></t-section>
		<t-row main-class="mb-30 fww tdb tdr">
			<t-checkbox type="p" size="small">石榴</t-checkbox>
			<t-checkbox type="p" size="small">橙子</t-checkbox>
			<t-checkbox type="p" size="small">香蕉</t-checkbox>
			<t-checkbox type="p" size="small">橙子</t-checkbox>
		</t-row>
		<t-section title="size-mini" main-class="mb-30 fww"></t-section>
		<t-row main-class="mb-30 fww tdb tdr">
			<t-checkbox type="p" size="mini">石榴</t-checkbox>
			<t-checkbox type="p" size="mini">橙子</t-checkbox>
			<t-checkbox type="p" size="mini">香蕉</t-checkbox>
			<t-checkbox type="p" size="mini">橙子</t-checkbox>
		</t-row>
		<t-row main-class="mb-30 fww tdb tdr">
			<t-section title="自定义图标 自定义样式 " main-class="mb-30"></t-section>
			<t-checkbox type="primary" :transition="true" main-class="s-80" label-class="c-#666">梨子</t-checkbox>
			<t-checkbox type="warning" :transition="true" active-class="bg-blue" active-label-class="c-red s-20"
				inactive-label-class="c-blue s-30">梨子</t-checkbox>
		</t-row>
		<t-section title="动态增删" main-class="mb-30"></t-section>
		<t-row main-class="mb-30 fww tdb tdr">
			<t-checkbox v-for="(item,index) in list" :key="index" icon="checkbox-blank-circle-fill"
				active-icon-class="s-20" type="primary" size="l" :transition="true">{{item.label}}</t-checkbox>
		</t-row>
		<t-row>
			<t-button size="mini" main-class="mr-20" type="p" @click="add">增加</t-button>
			<t-button size="mini" type="e" @click="del">删除</t-button>
		</t-row>
		<t-section title="按钮模式" main-class="mtb-30"></t-section>
		<t-row main-class="mb-30 fww tdb tdr">
			<t-checkbox main-class="mrb-10" size="large" active-class="bg-#fff" inactive-class="bg-#000"
				active-label-class="c-#000" inactive-label-class="c-#fff" type="primary" mode="button">石榴</t-checkbox>
			<t-checkbox main-class="mrb-10" size="medium" type="warning" mode="button" effect="l">橙子</t-checkbox>
			<t-checkbox main-class="mrb-10" size="small" type="success" mode="button" effect="d">香蕉</t-checkbox>
			<t-checkbox main-class="mrb-10" size="mini" type="error" mode="button">橙子</t-checkbox>
			<t-checkbox main-class="mrb-10" size="mini" type="warning" mode="button">梨子</t-checkbox>
		</t-row>
		<t-col main-class="mb-30 fww tdb tdr">
			<t-checkbox main-class="mb-10" type="primary" mode="button" size="large">石榴</t-checkbox>
			<t-checkbox main-class="mb-10" type="warning" mode="button" size="medium">橙子</t-checkbox>
			<t-checkbox main-class="mb-10" type="success" mode="button" size="small">香蕉</t-checkbox>
			<t-checkbox main-class="mb-10" type="error" mode="button" size="mini">橙子</t-checkbox>
			<t-checkbox main-class="mb-10" type="info" mode="button" size="mini">梨子</t-checkbox>
		</t-col>
		<t-section title="列表模式" main-class="mtb-30"></t-section>
		<t-col main-class="tdb tdr">
			<t-checkbox size="l" type="primary" mode="cell" :transition="true">石榴</t-checkbox>
			<t-checkbox size="l" type="warning" icon="thumb-up" active-icon-class="ats-0.5" mode="cell"
				:transition="true">橙子</t-checkbox>
			<t-checkbox size="l" type="success" icon="checkbox-blank-circle-fill" icon-class="ats-0.5"
				mode="cell">香蕉</t-checkbox>
			<t-checkbox size="l" type="error" mode="cell" :transition="true">橙子</t-checkbox>
			<t-checkbox size="l" type="warning" mode="cell" :transition="true">梨子</t-checkbox>
		</t-col>
	</t-page>
</template>

<script setup>
	import { TuiGuid } from '@/uni_modules/tui-plugins'
	type radiolisttype = {
		value : string
		label : string
	}
	const list = ref<radiolisttype[]>([
		{ value: '1', label: '石榴' },
		{ value: '2', label: '橙子' },
		{ value: '3', label: '香蕉' },
		{ value: '4', label: '橙子' },
		{ value: '5', label: '梨子' }
	] as radiolisttype[])
	function add() {
		list.value.push({
			value: TuiGuid(10),
			label: TuiGuid(10)
		} as radiolisttype)
	}
	function del() {
		list.value.splice(1, 1)
	}
</script>

属性

名称类型默认值说明可选值
sizeStringmini组件尺寸large(大尺寸), medium(中尺寸), small(小尺寸), mini(迷你)
typeString""组件类型info(信息), primary(正常), error(错误), warning(警告), success(成功)
disabledBooleanfalse组件是否禁用false, true
stopBooleanfalse是否阻止事件冒泡(Tui统一写法处理事件冒泡)false, true
hoverBooleantrue是否有点击效果false, true
pathString""点击组件后跳转的页面路径,如果为空则响应点击事件,如果不为空则跳转页面不会响应单击事件。-
mainClassString""组件根节点的样式-
nativeClassString""组件根节点原生样式-
effectString"normal"组件显示主题normal(正常), dark(深色), light(浅色), plain(镂空)
transitionBooleanfalse是否开启图标动画
checkedBooleanfalse是否被选中
valueString``当前选中的值
borderBooleantrue是否显示边框
durationNumber200图标动画时间
labelClassString``标签的样式
iconBoxClassString``图标盒子的样式
inactiveClassString``未选中时的样式
activeIconClassString``被选中是图标的样式
activeLabelClassString``被选中是标签的样式
modeStringcheckbox筛选框的样式checkbox: 复选框框样式
cell: 列表模式
button: 按钮模式
labelString``标签
iconStringcheck-fill图标
activeClassString``被选中时的样式
iconClassString``图标样式
inactiveIconClassString``未被选中时图标的样式
inactiveLabelClassString``未被选中是标签的样式

事件

名称返回参数说明
change选中的状态复选框状态变化时触发
click(e : UniPointerEvent)点击时触发

插槽

名称返回值说明
default-