-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
map-props.vue
86 lines (82 loc) 路 1.61 KB
/
map-props.vue
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
<template>
<FormProvider :form="form">
<Form layout="vertical">
<Field
name="name"
title="Name"
required
:decorator="[FormItem]"
:component="[Input, { placeholder: 'Please Input' }]"
/>
<FormConsumer>
<template #default="{ form }">
<div style="white-space: pre; margin-bottom: 16px">
{{ JSON.stringify(form.values, null, 2) }}
</div>
<Button
type="primary"
@click="
() => {
form.submit(log)
}
"
>
Submit
</Button>
</template>
</FormConsumer>
</Form>
</FormProvider>
</template>
<script>
import { Form, Input, Button } from 'ant-design-vue'
import { createForm, setValidateLanguage } from '@formily/core'
import {
FormProvider,
FormConsumer,
Field,
connect,
mapProps,
} from '@formily/vue'
import 'ant-design-vue/dist/antd.css'
setValidateLanguage('en')
const FormItem = connect(
Form.Item,
mapProps(
{
title: 'label',
description: 'extra',
required: true,
validateStatus: true,
},
(props, field) => {
return {
...props,
help: field.selfErrors?.length ? field.selfErrors : undefined,
}
}
)
)
export default {
components: {
FormProvider,
FormConsumer,
Field,
Form,
Button,
},
data() {
const form = createForm({ validateFirst: true })
return {
FormItem,
Input,
form,
}
},
methods: {
log(...args) {
console.log(...args)
},
},
}
</script>