np-form Form

A configuration-driven form that dynamically generates the form through columns, simple to use and highly extensible.

Basic Usage

Form fields are mainly configured with label, key, type to set the form label, form field and field type. More config depends on the props of the actual type once type is set.

浏览器不支持,请手动复制 basic.en.vue

Component Configuration

Props

PropDescriptionTypeDefault
optionConfigurationFormOption-

Methods

After getting the form instance via ref, you can imperatively call the following methods. See Imperative Methods.

MethodDescriptionType
submitSubmit the form manually() => Promise<void>
resetReset the form and trigger onReset() => Promise<void>
validateFieldsValidate the given fields, supports __ prefix matching(fields: string | string[]) => Promise<void>

Types

The component exports the following type definitions:

import type { FormOption } from 'naive-plus'

FormOption

PropDescriptionTypeDefault
columnsForm fieldsArray<FormColumn>-
onSubmitSubmit event(data)=>Promise<void>-
onResetReset event(data)=>Promise<void>-
propsForm propsobject-

FormColumn

PropDescriptionTypeDefault
labelField labelstring / VNode-
keyForm field namestring-
typeForm field typestring / (data)=>VNode-
defaultValueDefault valueany-
optionsDictionary options, e.g. checkbox, select, etc.Array<any> / ()=>Promise<Array<any>>-
propsComponent props, passed through to the actual componentobject-
formItemPropsForm item props, passed through to n-form-itemobject-