CondorDictCheckbox
CondorDictCheckbox 是一个基于字典数据的复选框组件,用于显示动态字典选项并支持多选操作。该组件与字典存储(Pinia Store)集成,自动加载指定字典编码的数据并渲染为复选框组。
组件 Props
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| code | string | - | 必需 字典编码,用于从字典存储中获取对应的字典数据列表 |
| value | string / Array<string , number> / null | null | 绑定的值,支持字符串(逗号分隔)、数组或null |
| type | 'number' / 'string' | 'string' | 值的类型,指定组件内部处理值的类型格式 |
| format | 'string' / 'array' | 'string' | 输出格式,控制组件输出的值是字符串(逗号分隔)还是数组 |
组件事件
| 事件名 | 说明 | 参数 |
|---|---|---|
| update:value | 当复选框选择变化时触发 | 更新后的值(根据format格式返回字符串或数组) |
基本用法
- 基本使用(字符串格式)
vue
<template>
<CondorDictCheckbox
code="gender"
v-model:value="selectedGenders"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue';
// 输出格式为字符串(默认):"male,female"
const selectedGenders = ref('male');
</script>- 使用数组格式
vue
<template>
<CondorDictCheckbox
code="education"
v-model:value="selectedEducation"
format="array"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue';
// 输出格式为数组:["1", "3"]
const selectedEducation = ref(['1', '3']);
</script>- 使用数字类型
vue
<template>
<CondorDictCheckbox
code="status"
v-model:value="statusValues"
type="number"
format="array"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue';
// 值会被转换为数字类型:[1, 2, 3]
const statusValues = ref([1, 2]);
</script>