Custom component

Form-create supports generating any vue component inside the form

::: tip Reminder

  • Only need to define the name attribute when you need to get the generation rules for this component via the $f.component() method.
  • When you need to have custom components and built-in components have the same functionality, you can convert them to form components

:::

Generate components by tag

Generate custom components by creating a virtual DOM

JSON generation

  1. {
  2. type: 'i-button',
  3. name: 'btn',
  4. props:{
  5. type: 'primary',
  6. field: 'btn',
  7. loading: true
  8. },
  9. children:['Loading']
  10. }

Maker generation

maker.create

  • Parameter:

    • {string} tab component name/tag name
    • {string} field
    • {string} title
  • Usage:

    1. formCreate.maker.create('i-button', 'btn', 'custom button')

Generation

  1. formCreate.maker.create('i-button').props({
  2. type: 'primary',
  3. field: 'btn'
  4. loading: true
  5. }).children(['Loading']).name('btn');

Modify

Get the component generation rules and modify them by $f.component() method

  1. $f.component().btn.props.loading = false;

Example

create-demo

  1. let rule = [
  2. {
  3. type: 'row',
  4. children:[
  5. {
  6. type: 'i-col',
  7. props:{
  8. span:12
  9. },
  10. children:[
  11. formCreate.maker.input('commodity name', 'goods_name', 'iphone'),
  12. formCreate.maker.number('Product plus one', 'goods_price', 8688)
  13. ]
  14. },
  15. {
  16. type: 'i-col',
  17. props:{
  18. span:12
  19. },
  20. children:[
  21. formCreate.maker.dateTime('creation time', 'create_at'),
  22. formCreate.maker.radio('Do you want ','is_show').options([
  23. {value:1,label:'Show '},
  24. {value:0,label:'Do not display'}
  25. ])
  26. ]
  27. }
  28. ]
  29. }
  30. ]

Generating components from templates

Generate custom components by template

JSON generation

  1. {
  2. type: 'template',
  3. name:'btn'
  4. template:'<i-button :loading="loading">{{text}}<i-button>',
  5. vm: new Vue({
  6. data:{
  7. loading: true,
  8. text: 'Loading'
  9. }
  10. })
  11. }

Maker generation

  • Parameter:

    • {string} template
    • {Vue} vm
    • {string} field = undefined
    • {string} title = undefined
  • Usage:

    1. formCreate.maker.template('<i-button></i-button>', new Vue, 'btn', 'custom button')

maker.template

  1. formCreate.maker.template('<i-button :loading="loading">{{text}}</i-button>',new Vue({
  2. data:{
  3. loading: true,
  4. text: 'Loading...'
  5. }
  6. })).name('btn')

Modify

The internal values ​​of the vm component can be dynamically modified in two ways.

Get the vm of the custom component via rule and modify it

  1. rule.vm.text = 'Load completed';
  2. rule.vm.loading = false;

Get vm of custom component and modify it by $f.component() method

  1. $f.component().btn.vm.text = 'Load completed';
  2. $f.component().btn.vm.loading = false;

If the modified component is not updated, force a refresh via $.sync or $f.refresh