# Global API
Call method:
Global
formCreate.parseJson(json)
Vue
vm.$formCreate.parseJson(json)
# create
Type:
FunctionParameters:
ArrayrulesObjectoptions
Return value:
ObjectfApi
Description: Generate form
Usage:
const fApi = formCreate.create(rules, options)
# use v2.5.0+
Type:
FunctionParameters:
Function|Objectrules
Description:
Install the formCreate plugin. If the plug-in is an object, the install method must be provided. If the plugin is a function, it will be used as the install method. When the install method is called, formCreate is passed in as Parameters.
This method needs to be called before the form is generated.
# init
Type:
FunctionParameters:
ArrayrulesObjectoptions
Return value:
FunctionmountFunctionremoveFunctiondestroyObject$f
Description:Create a form builder
Usage:
const {$f,mount,remove,destroy} = formCreate.init(rules,options) //Mount the form to #app mount(document.getElementById('app')) //Destroy form remove()
# component
Type:
FunctionParameters:
stringidObjectcomponent
Description:Mount custom components in form-create
Usage:
//Mount formCreate.component('test',component) //Get Component const component = formCreate.component('test')
# directive v2.5.0+
Type:
FunctionParameters:
stringidObjectdirective
Description:Mount custom directive in form-create
Usage:
//Mount formCreate.directive('test',directive)
# register v2.5.0+
Type:
FunctionParameters:
stringidObjecteffect
Description:Mount custom attribute extension
Usage:
//Mount formCreate.register(effect)
# createParser < v2.5.0
Type:
FunctionReturn value:
Parserparser
Description: Create a new component parser
Usage:
const Parser = formCreate.createParser()
# setParser < v2.5.0
Type:
FunctionParameters:
stringcomponentNameParserparser
Description:Bind a component parser
Usage:
const Parser = formCreate.createParser() Parser.prototype.toFormValue = (value)=>parseFloat(value)||0 formCreate.setParser('inputNumber',Parser)
# parser v2.5.0+
Type:
FunctionParameters:
Objectparser
Description:Bind a component resolver
Usage:
formCreate.parser({ name:'input', toFormValue(val){ return parseFloat(val)||0 } })
# maker
Type:
ObjectDescription:Maker
Usage:
rule = maker.input('testTitle','testField','testValue')
# componentAlias v2.5.0+
Type:
ObjectDescription:Set the alias of the component
Usage:
formCreate.componentAlias({btn:'ElButton'})
# $form
Type:
FunctionDescription: Bind a component parser
Usage:
$formCreate = formCreate.$form() //Partial mount formCreate new Vue({ components:{ 'form-create':$formCreate } }) //Global mount Vue.component('form-create',$formCreate)
# parseJson v0.0.4+
Type:
FunctionParameters:
StringjsonBooleanmode v1.0.5
Description:Convert json to generation rules, add a second parameter for backward compatibility, use the new version to parse when
mode:true(version>1.0.5 recommends that the second parameter is fixed to true)Usage:
const json = fApi.toJson() const rule = formCreate.parseJson(json, true)
# toJson v2.5.3+
Type:
FunctionParameters:
StringRule[]string | numberspace
Description:Convert the specified generation rules to JSON
# fetch v2.5.3+
Type:
type fetch = (options: { action: String; //Request method method?: String; //Call interface with data data?: Object; //Call the method of submitting data attached to the interface,The default is `formData` dataType?: 'json'; //Custom header information headers?: Object; //Callback for successful interface call onSuccess: (body: any) => void //Interface call failure callback onError?: (e: Error | ProgressEvent) => void; })=> void;Description:Built-in fetch, used to load data
# copyRules v2.5.0+
Type:
FunctionParameters:
arrayrules
Description:Copy generation rules
Usage:
const rules = formCreate.copyRules(rules)
# copyRule v2.5.0+
Type:
FunctionParameters:
arrayrule
Description:Copy generation rule
Usage:
const rule = formCreate.copyRule(rule)
# vm.$formCreate
Type:
FunctionParameters:
ArrayrulesObjectoptions
Return value:
Object$f
Property:all of above
Description: Generate form
Usage:
new Vue({ mounted(){ const fApi = this.$formCreate(rules,options) } })