Global API

create

  • Type:Function

  • Parameter:

    • Array rules
    • Object options
  • return value:

    • Object $f
  • Description: Generate form

  • Usage:

    1. const $f = formCreate.create(rules,options);

init

  • Type:Function

  • Parameter:

    • Array rules
    • Object options
  • return value:

    • Function mount mount form
    • Function remove remove form
    • Function destroy destroys the form
    • Object $f
  • Description: Create a form constructor

  • Usage:

    1. const {$f,mount,remove,destroy} = formCreate.init(rules,options);
    2. //mount the form to #app
    3. mount(document.getElementById('app'));
    4. //Destroy the form
    5. remove();

component

  • Type:Function

  • Parameter:

    • string id
    • Object component
  • Description: Mount custom components in form-create

  • Usage:

    1. //mount component
    2. formCreate.component('test',component);
    3. //get the component
    4. const component = formCreate.component('test');

createParser

  • Type:Function

  • return value:

    • Parser parser
  • Description: Create a new component parser

  • Usage:

    1. const Parser = formCreate.createParser();

setParser

  • Type:Function

  • Parameter:

    • string componentName
    • Parser parser
  • Description: Bind a component parser

  • Usage:

    1. const Parser = formCreate.createParser();
    2. parser.prototype.toFormValue = (value)=>parseFloat(value)||0;
    3. formCreate.setParser('inputNumber',Parser);

maker

  • type: Object

  • Description: Component Builder

  • Usage:

    1. rule = maker.input('testTitle','testField','testValue');

$form

  • Type:Function

  • Description: Bind a component parser

  • Usage:

    1. $formCreate = formCreate.$form();
    2. //Local mount formCreate
    3. new vue({
    4. components:{
    5. 'form-create': $formCreate
    6. }
    7. });
    8. //Global mount
    9. Vue.component('form-create',$formCreate);

parseJson

  • Type:Function

  • Parameter

    • String json
    • Boolean mode
  • Description: Convert json to a generation rule, 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:

    1. const json = $f.toJson();
    2. const rule = formCreate.parseJson(json, true);

Event

change

  • Parameter

    • field
    • value
    • $f api
  • Directions: Triggered when the value of the form component changes within the component

set-value

  • Parameter

    • field
    • value
    • $f api
  • Directions: Triggered when the value of the form component modified externally

emit-event

  • Parameter

    • emitName
    • ...args event Parameter
  • Directions: Triggered when the component’s emit event triggered

control

  • Parameter

    • rule rule
    • $f api
  • Directions: Triggered when the component’s control becomes effective or invalid

mounted

  • Parameter

    • $f api
  • Directions: Triggered after the form rendered for the first time

on-submit

  • Parameter

    • formData
    • $f api
  • Directions: Triggered when the form submit button clicked

vm.$formCreate

  • Type:Function

  • Parameter:

    • Array rules
    • Object options
  • return value:

    • Object $f
  • Attributes:

    • Function component
    • Function createParser
    • Function setParser
    • Function $form
    • Function parseJson
    • Object maker
  • Description: Generate form

  • Usage:

    1. new vue({
    2. mounted(){
    3. Const $f = this.$formCreate(rules,options);
    4. }
    5. })