index.vue
1.34 KB
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
<script>
export default {
name: 'FormItem',
props: {
label: String,
labelWidth: String,
value: [Number, String, Array, Boolean, Object],
prop: String,
span: {
type: [Number, String],
default() {
return this.zForm ? this.zForm.span : undefined;
},
},
},
provide() {
return {
zFormItem: this,
};
},
inject: {
zForm: {
default: undefined,
},
},
render(h) {
let scopedSlots = this.$scopedSlots;
let content = '';
if (scopedSlots.default) {
content = scopedSlots.default();
} else {
if (!scopedSlots.default) {
if (this.zForm && this.zForm.itemComponent) {
content = h(this.zForm.itemComponent, {
props: {
value: this.value,
...this.$attrs,
},
on: {
input: value => {
this.$emit('input', value);
},
},
});
} else {
content = this.value;
}
}
}
return h('el-col', { props: { span: this.span ? Number(this.span) : undefined } }, [
h(
'el-form-item',
{
props: { label: this.label, 'label-width': this.labelWidth, prop: this.prop, ...this.$attrs },
scopedSlots,
},
[content],
),
]);
},
};
</script>