VForm ​

VForm is a configuration-driven form component built on top of el-form. It renders form fields from a form-items array, supports built-in submit / reset buttons, and exposes validation helpers for parent components.

Basic Usage ​

Basic form with form-items configuration.

Name
Email
City
Select

Inline Layout ​

Set inline to display form fields in a row.

Name
Age

With Buttons ​

Set show-button to display the built-in submit and reset buttons.

Name
Email

Validation ​

Use rules on the form or field-level validation options in form-items.

Name
Email

Behavior Notes ​

  • Prefer v-model as the main data source. model is also supported, but using both at the same time can make updates harder to reason about.
  • show-button controls the built-in action row. Use the buttonArea slot to replace the default submit / reset buttons.
  • auto-submit-on-enter only submits when the pressed target is an input element. It intentionally does not block textarea line breaks.
  • default-value initializes a field and is restored again when doReset() runs.
  • required and reg on a form item generate validation rules automatically. message-with-prop prepends the field label to the generated message.
  • For built-in el-input, the component applies a default maxlength of 256, or 1024 when type="textarea", unless you override it in attrs.
  • Built-in element shortcuts include el-input, el-input-number, el-select, el-checkbox, el-date-picker, and el-switch. Other component names are rendered dynamically as provided.

API ​

VForm Attributes ​

NameDescriptionTypeDefault
model-value / v-modelform data objectobject{}
modelalternative form data object sourceobject{}
form-itemsform item configuration listarray[]
rulesextra validation rules passed to the inner el-formobject{}
inlinewhether to render as an inline formbooleantrue
label-positionform label positionenum'right'
label-widthdefault label width for generated form itemsstring / number'160px'
input-widthdefault input width for generated controlsstring / number'240px'
class-namecustom class name appended to the root .v-formstring''
sizesize of inner form controlsenum''
disabledwhether to disable the whole formbooleanfalse
auto-submit-on-entersubmit the form when Enter is pressed in an input elementbooleanfalse
show-buttonwhether to show the built-in action buttonsbooleanfalse
show-submit-buttonwhether to show the built-in submit buttonbooleantrue
show-reset-buttonwhether to show the built-in reset buttonbooleantrue

FormItem Configuration ​

NameDescriptionTypeDefault
propfield keystring—
labelfield labelstring—
label-rendercustom label renderer for the el-form-item label slotfunction—
label-widthlabel width for the current fieldstring / number—
elementrendered control or component namestring'el-input'
attrsattributes / props forwarded to the rendered controlobject—
item-propsprops forwarded to the wrapping el-form-itemobject—
rulesvalidation rules used by the current fieldarray—
titletitle attribute passed to el-form-itemstring—
disabledwhether to disable the current fieldbooleanfalse
input-widthwidth of the current rendered controlstring / number—
optionsoption list used by el-selectarray—
rendercustom renderer that replaces the built-in controlfunction—
formatterformatter applied before committing a changed valuefunction—
typeextra control type such as input type or textarea modestring—
auto-submit-on-enteremit value-change with action enter when Enter is pressed in supported inputsbooleanfalse
replace-regremove matching characters during input synchronizationRegExp—
requiredgenerate a built-in required rulebooleanfalse
reggenerate a built-in pattern validation ruleRegExp—
message-with-propprepend the field label to generated required / pattern messagesbooleanfalse
default-valueinitial value for the field and reset target used by doReset()any—
hidewhether to skip rendering the current fieldbooleanfalse

Extra fields on each form item are forwarded to the rendered control as component props / attributes. Use this for settings such as placeholder, clearable, filterable, min, max, format, and similar control-specific options.

VForm Events ​

NameDescriptionType
update:model-valueemitted when the form model changesfunction
value-changeemitted when a field value changesfunction
submitemitted after validation succeedsfunction
resetemitted after the built-in reset logic runsfunction
throw-form-el-refemitted on mount with the inner el-form instance referencefunction

VForm Slots ​

NameDescription
formHeadercustom content rendered before the generated form items; slot props: { formModel }
defaultcustom content rendered after the generated form items; slot props: none
formFootercustom content rendered after the default slot; slot props: { formModel }
buttonAreacustom action area that replaces the built-in buttons; slot props: { formModel }

Exposes ​

NameDescriptionType
validatevalidate the inner el-form; resolves on success and rejects on failurefunction
clearValidateclear validation state for all fields or the specified fieldsfunction
handleSubmitrun validation and emit submit; returns the form model when validfunction
doResetreset configured fields to default-value or remove their keys, then emit resetfunction

Source ​

Docs