修改表单规则

在尾部追加规则

::: demo

  1. <template>
  2. <div>
  3. <form-create :rule="rule" v-model="fApi" :option="options"/>
  4. <h2>操作</h2>
  5. <p>在表单尾部追加组件</p>
  6. <ElButton @click="append1">方式1</ElButton>
  7. <ElButton @click="append2">方式2</ElButton>
  8. <p>在inputNumber组件底部追加组件</p>
  9. <ElButton @click="set1">方式1</ElButton>
  10. <ElButton @click="set2">方式2</ElButton>
  11. </div>
  12. </template>
  13. <script>
  14. export default {
  15. data(){
  16. return {
  17. i: 0,
  18. fApi:{},
  19. options:{
  20. submitBtn:false,
  21. resetBtn:false
  22. },
  23. rule:[
  24. {
  25. type:'inputNumber',
  26. field:'number',
  27. title:'库存',
  28. value: 0
  29. },
  30. {
  31. type:'input',
  32. field:'info',
  33. title:'简介',
  34. value: '',
  35. props:{
  36. type:'textarea'
  37. }
  38. }
  39. ]
  40. }
  41. },
  42. methods:{
  43. getRule(){
  44. this.i++;
  45. return this.$formCreate.maker.input('追加组件'+this.i,'input'+this.i,'');
  46. },
  47. append1(){
  48. this.rule.push(this.getRule());
  49. },
  50. append2(){
  51. this.fApi.append(this.getRule());
  52. },
  53. set1(){
  54. this.rule.splice(1,0,this.getRule());
  55. },
  56. set2(){
  57. this.fApi.append(this.getRule(), 'number');
  58. }
  59. }
  60. }
  61. </script>

:::

在顶部增加规则

::: demo

  1. <template>
  2. <div>
  3. <form-create :rule="rule" v-model="fApi" :option="options"/>
  4. <h2>操作</h2>
  5. <p>在表单顶部增加组件</p>
  6. <ElButton @click="append1">方式1</ElButton>
  7. <ElButton @click="append2">方式2</ElButton>
  8. <p>在input组件顶部增加组件</p>
  9. <ElButton @click="set1">方式1</ElButton>
  10. </div>
  11. </template>
  12. <script>
  13. export default {
  14. data(){
  15. return {
  16. i: 0,
  17. fApi:{},
  18. options:{
  19. submitBtn:false,
  20. resetBtn:false
  21. },
  22. rule:[
  23. {
  24. type:'inputNumber',
  25. field:'number',
  26. title:'库存',
  27. value: 0
  28. },
  29. {
  30. type:'input',
  31. field:'info',
  32. title:'简介',
  33. value: '',
  34. props:{
  35. type:'textarea'
  36. }
  37. }
  38. ]
  39. }
  40. },
  41. methods:{
  42. getRule(){
  43. this.i++;
  44. return this.$formCreate.maker.input('追加组件'+this.i,'input'+this.i,'');
  45. },
  46. append1(){
  47. this.rule.splice(0,0,this.getRule());
  48. },
  49. append2(){
  50. this.fApi.prepend(this.getRule());
  51. },
  52. set1(){
  53. this.fApi.prepend(this.getRule(), 'info');
  54. }
  55. }
  56. }
  57. </script>

:::

添加组件的子组件

::: demo

  1. <template>
  2. <div>
  3. <form-create :rule="rule" v-model="fApi" :option="options"/>
  4. <h2>操作</h2>
  5. <p>在 col 组件内部增加</p>
  6. <ElButton @click="append1">方式1</ElButton>
  7. <ElButton @click="append2">方式2</ElButton>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. data(){
  13. return {
  14. i: 0,
  15. fApi:{},
  16. options:{
  17. submitBtn:false,
  18. resetBtn:false
  19. },
  20. rule:[
  21. {
  22. type:'el-col',
  23. title:'布局组件',
  24. name: 'col',
  25. children: []
  26. }
  27. ]
  28. }
  29. },
  30. methods:{
  31. getRule(){
  32. this.i++;
  33. return this.$formCreate.maker.input('追加组件'+this.i,'input'+this.i,'');
  34. },
  35. append1(){
  36. this.rule[0].children.push(this.getRule());
  37. },
  38. append2(){
  39. this.fApi.append(this.getRule(),'col', true);
  40. }
  41. }
  42. }
  43. </script>

:::

删除第一条规则

  1. rule.splice(0,1);

删除表单组件

  1. fApi.removeField('field');

删除自定义组件

  1. $f.removeField('name');