Skip to content

CheckButton 复选框按钮组件

该组件内部实现以tag二次封装按钮复选框和单选框

📌平台差异说明

APP(vue)H5微信小程序支付宝小程序

🏯基本使用示例

html
<template>
    <!-- 全局使用 -->
    <hy-check-button v-model="value" :columns="columns"></hy-check-button>
</template>

<script lang="ts" setup>
    import { reactive, ref } from 'vue';

    const value = ref('');
    const columns = reactive([
        { label: '老师', value: 0 },
        { label: '护士', value: 1 },
        { label: '空姐', value: 2 },
        { label: '作家', value: 3 },
        { label: '网红', value: 4 },
        { label: '科学家', value: 5 },
    ]);
</script>

主题色

  • 通过type设置配置主题色
    • primary:信息按钮(默认)
    • success:主要按钮
    • info:默认按钮
    • warning:警告按钮
    • error:危险按钮
html
<hy-check-button v-model="value" :columns="columns" :type="type"></hy-check-button>
ts
import { reactive, ref } from 'vue';

const value = ref('');
const type = ref<HyApp.ThemeType>('primary');

const columns = reactive([
    { label: '老师', value: 0 },
    { label: '护士', value: 1 },
    { label: '空姐', value: 2 },
    { label: '作家', value: 3 },
    { label: '网红', value: 4 },
    { label: '科学家', value: 5 },
]);

配置按钮大小

  • 通过size设置配置按钮大小
    • large 大的
    • medium 中等的
    • small 小的
html
<hy-check-button v-model="value" :columns="columns" :type="type"></hy-check-button>
ts
import { reactive, ref } from 'vue';

const value = ref('');
const type = ref<HyApp.SizeType>('medium');

const columns = reactive([
    { label: '老师', value: 0 },
    { label: '护士', value: 1 },
    { label: '空姐', value: 2 },
    { label: '作家', value: 3 },
    { label: '网红', value: 4 },
    { label: '科学家', value: 5 },
]);

配置形状

  • 通过shape值设置按钮形状;
    • square为方形(默认)
    • circle为圆角
html
<hy-check-button v-model="value" :columns="columns" :shape="shape"></hy-check-button>
ts
import { reactive, ref } from 'vue';

const value = ref('');
const type = ref<HyApp.ShapeType>('square');

const columns = reactive([
    { label: '老师', value: 0 },
    { label: '护士', value: 1 },
    { label: '空姐', value: 2 },
    { label: '作家', value: 3 },
    { label: '网红', value: 4 },
    { label: '科学家', value: 5 },
]);

单选按钮

  • 通过selectType设置为radio
html
<hy-check-button v-model="value" :columns="columns" selectType="radio"></hy-check-button>
ts
import { reactive, ref } from 'vue';

const value = ref('');

const columns = reactive([
    { label: '老师', value: 0 },
    { label: '护士', value: 1 },
    { label: '空姐', value: 2 },
    { label: '作家', value: 3 },
    { label: '网红', value: 4 },
    { label: '科学家', value: 5 },
]);

多选按钮

  • 通过selectType设置为checkbox
html
<hy-check-button v-model="value" :columns="columns" selectType="checkbox"></hy-check-button>
ts
import { reactive, ref } from 'vue';

const value = ref([0]);

const columns = reactive([
    { label: '老师', value: 0 },
    { label: '护士', value: 1 },
    { label: '空姐', value: 2 },
    { label: '作家', value: 3 },
    { label: '网红', value: 4 },
    { label: '科学家', value: 5 },
]);

API

参数说明类型默认值
v-model选中得值[1]string|number| (string|number)[]-
columns列表数据array-
fieldNames自定义columns对应得键object{label: "label",value: "value",checked: "checked"}
selectType单选还是多选[2]checkbox|radiocheckbox
disabled禁用booleanfalse
col设置子元素列排序,参考css属性值grid-template-columnsstringrepeat(3, 1fr)
gap设置每行间距,数值默认单位pxstring| number10px
type标签类型[3]error|warning|success |primary|infoprimary
size标签的大小[4]small|medium|largemedium
shapetag的形状[5]circle|squaresquare

columns

参数说明类型默认值
label显示文本内容string-
valuestring-
checked是否选中boolean-
disabled是否禁用boolean-

API

参数说明类型默认值
label自定义columns的文本键stringlabel
value自定义columns的值键stringvalue
checked自定义columns的选中键stringchecked

Events

事件名说明回调参数
change选择触发-

Slots

插槽名说明接收值
name--
03:29

  1. selectType设置为radio时候v-model必须传是字符串/数字,设置为checkbox时候v-model必须传数组 ↩︎

  2. checkbox:多选;radio:单选 ↩︎

  3. error:#fa3534;warning:#ff9900;success:#19be6b;primary:#2979ff; info:#909399; ↩︎

  4. normal:默认尺寸;large:大尺寸; small:小尺寸; ↩︎

  5. circle:两边半圆形; square:方形,带圆角 ↩︎