forked from Project-HAMi/HAMi-WebUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormRender.vue
More file actions
83 lines (77 loc) · 1.89 KB
/
Copy pathFormRender.vue
File metadata and controls
83 lines (77 loc) · 1.89 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<template>
<template v-for="item in formItems">
<form-group
v-if="item.children"
v-bind="item"
:label="item.label"
:component="item.component"
:label-width="labelWidth"
:componentProps="item.props"
:key="item.name"
>
<template v-for="c in item.children">
<form-group
v-if="c.children"
:label="c.label"
:component="c.component"
:label-width="labelWidth"
:key="c.name"
:componentProps="c.props"
:help="c.help"
>
<FormRender
:labelWidth="labelWidth"
v-model="form"
:formItems="c.children"
:key="c.label"
/>
</form-group>
<form-item
v-else
v-model="formValues[c.name]"
v-bind="c"
:label-width="labelWidth"
:componentProps="c.props"
:key="c.label"
/>
</template>
</form-group>
<form-item
v-else
v-model="formValues[item.name]"
v-bind="item"
:label-width="labelWidth"
:componentProps="item.props"
:key="item.label"
/>
</template>
</template>
<script setup>
import { computed } from 'vue';
import FormItem from './FormItem.vue';
import FormGroup from './FormGroup.vue';
const props = defineProps({
labelWidth: String,
modelValue: Object,
formItems: Array,
});
const emit = defineEmits(['update:modelValue']);
//原form总数据源
const form = computed({
get() {
return props.modelValue;
},
set(val) {
emit('update:modelValue', val);
},
});
// 通过Proxy接管的数据源,某项属性被修改会立刻通知父组件,遵守单项数据流原则
const formValues = computed(() => {
return new Proxy(props.modelValue, {
set(target, key, value) {
emit('update:modelValue', { ...target, [key]: value });
return true;
},
});
});
</script>