# 自定义组件 component
<template>
<div class="demo-box">
<form-builder ref="formBuilder" v-model="formModel" :form-data="formData">
<template slot="actions">
<el-form-item>
<el-button type="primary" @click="handleSubmit">提交</el-button>
</el-form-item>
<pre>{{ formModel }}</pre>
</template>
</form-builder>
</div>
</template>
<script>
import CustomInput from '../CustomInput'
import CustomWidget from '../CustomWidget'
export default {
components: {
CustomInput,
CustomWidget
},
data() {
return {
formModel: {
customInput: '',
day: '',
mankind: ''
},
formData: {
config: {
labelWidth: '120px',
rules: {
customInput: [
{ required: true, message: '请输入正数' }
],
mankind: [
{ required: true, message: '请输入人数' }
],
day: [
{ required: true }
]
}
},
list: [{
component: CustomInput,
label: '自定义输入框',
model: 'customInput',
attrs: {
placeholder: '只能输入正数'
},
events: {
change: data => {
this.formModel.customInput = data
}
}
}, {
component: CustomWidget,
label: '自定义组合',
model: 'day',
attrs: {
defaultDay: 60,
defaultMankind: 20,
dayOptions: [{
value: 30,
label: 30
} ,{
value: 60,
label: 60
}, {
value: 90,
label: 90
}]
},
events: {
change: data => {
this.formModel.day = data.day
this.formModel.mankind = data.mankind
}
}
}]
}
}
},
methods: {
handleSubmit() {
this.$refs.formBuilder.getModel().then(model => {
console.log(model)
})
}
}
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93