Skip to content

generateFormData

生成表单字段初始值对象

代码示例

ts
const fields = defineForm([
  {
    type: Form.Divider,
    title: '基本信息',
    props: {
      contentPosition: 'left'
    }
  },
  {
    type: Form.Input,
    field: 'name',
    formItemProps: {
      label: '姓名',
    },
    props: {
      placeholder: '请输入姓名',
      clearable: true,
      onChange: (e: any) => {
        console.log(e)
      },
      onClear: () => {
        console.log('clear')
      }
    }
  },
  {
    type: Form.RadioGroup,
    field: 'sex',
    formItemProps: {
      label: '性别',
    },
    options: [
      { label: '男', value: '1' },
      { label: '女', value: '2' },
    ],
    labelField: 'label',
    valueField: 'value',
    radioProps: {
      border: true,
    }
  },
  {
    type: Form.Divider,
    title: '其他信息',
    props: {
      contentPosition: 'left'
    }
  },
  {
    type: Form.InputNumber,
    field: 'age',
    formItemProps: {
      label: '年龄',
    },
    props: {
      placeholder: '请输入年龄',
      min: 1,
      max: 120,
      precision: 0,
      controlsPosition: 'right',
      style: {
        width: '220px'
      }
    }
  },
  {
    type: Form.Custom,
    field: 'birthday',
    formItemProps: {
      label: '出生日期',
    },
    initValue: '',
  }
])

const { fields, initFormData } = generateFormData(fields);

参数

参数说明类型默认值
fields表单字段配置FormFieldItem[]-

返回值

参数说明类型
initData表单字段初始值对象{ fields: string[], initFormData: {[key: string]: any} }