本章节介绍 Schema FormX 的基础功能,包括表单配置、字段类型等核心概念。掌握这些基础知识后,您就可以开始构建简单的表单了。
表单配置是 Schema FormX 的核心,通过配置来定义表单的结构和行为。
Schema FormX 支持以下字段类型:
const schema: FieldSchema[] = [ { type: 'string', name: 'username', label: '用户名', required: true, props: { placeholder: '请输入用户名' } }, { type: 'number', name: 'age', label: '年龄', props: { min: 0, max: 120 } }, { type: 'boolean', name: 'agree', label: '同意协议' } ];
布局配置控制表单的整体样式和布局:
const layout: Layout = { formClassName: 'my-form', formStyle: { maxWidth: '600px' }, fieldClassName: 'form-field', labelClassName: 'field-label', controlClassName: 'field-control' };
Schema FormX 支持自定义表单控件:
const components = { DefaultControl: MyInputComponent, CustomSelect: MySelectComponent }; <Form components={components} schema={schema} />
const schema: FieldSchema[] = [ { type: 'string', name: 'status', label: '状态', component: 'CustomSelect', props: { options: ['启用', '禁用'] } } ];