Skip to content

Group 表单分组 ​

表单分组组件,用于将多个表单项组合在一起,形成分组展示。

类型标识 ​

  • t: 'group'

额外 Props ​

属性名类型默认值描述
labelstring-分组标题
configJSONFormOption[] | ((option: ConfigOption) => JSONFormOption[])-子级表单项配置
cellGroupPropsPartial<CellGroupProps>-VanCellGroup 组件的属性
cellGroupOnobject{}VanCellGroup 组件的事件
cellGroupSlotsobject-VanCellGroup 组件的插槽

示例 ​

基础用法 ​

typescript
const formConfig = defineOption([
    {
        field: 'userInfo',
        t: 'group',
        label: '用户信息',
        config: [
            {
                field: 'username',
                t: 'input',
                label: '用户名',
                placeholder: '请输入用户名',
            },
            {
                field: 'email',
                t: 'input',
                label: '邮箱',
                placeholder: '请输入邮箱',
            },
        ],
    },
    {
        field: 'addressInfo',
        t: 'group',
        label: '地址信息',
        config: [
            {
                field: 'province',
                t: 'picker',
                label: '省份',
                placeholder: '请选择省份',
            },
            {
                field: 'city',
                t: 'picker',
                label: '城市',
                placeholder: '请选择城市',
            },
        ],
    },
]);

动态分组配置 ​

typescript
const formConfig = defineOption(({ query }) => [
    {
        field: 'userInfo',
        t: 'group',
        label: '用户信息',
        config: [
            {
                field: 'username',
                t: 'input',
                label: '用户名',
                disabled: !query.email,
            },
            {
                field: 'email',
                t: 'input',
                label: '邮箱',
            },
        ],
    },
]);