Skip to content

Commit cd6b136

Browse files
committed
Add documentation for "components" property
1 parent eec6189 commit cd6b136

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

docs/api/components.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# components
2+
3+
With Vue one can use both locally and globally registered components. If not all the components you want to use are globally registered you can use the `components` property to pass in additional components to `vue-form-json-schema`.
4+
5+
## Provide locally registered components
6+
7+
In this example we re-use the locally registered components and pass them along to `vue-form-json-schema`
8+
9+
```html
10+
<template>
11+
<vue-form-json-schema
12+
v-model="model"
13+
:schema="schema"
14+
:ui-schema="uiSchema"
15+
:components="$options.components"
16+
/>
17+
</template>
18+
19+
<script>
20+
import MyComponent from "./MyComponent"
21+
22+
export default {
23+
components: {
24+
"my-component": MyComponent
25+
},
26+
data() {
27+
return {
28+
model: {
29+
firstName: "John",
30+
},
31+
schema: {
32+
type: 'object',
33+
properties: {
34+
firstName: 'string'
35+
}
36+
},
37+
uiSchema: [{
38+
component: "my-component",
39+
model: 'firstName',
40+
fieldOptions: {
41+
on: ['input']
42+
}
43+
}]
44+
}
45+
}
46+
}
47+
</script>
48+
```
49+
50+
## Use components directly without registering them
51+
52+
In this example we pass the components along to `vue-form-json-schema` without registering them first
53+
54+
```html
55+
<template>
56+
<vue-form-json-schema
57+
v-model="model"
58+
:schema="schema"
59+
:ui-schema="uiSchema"
60+
:components="components"
61+
/>
62+
</template>
63+
64+
<script>
65+
import MyComponent from "./MyComponent"
66+
67+
export default {
68+
data() {
69+
return {
70+
model: {
71+
firstName: "John",
72+
},
73+
schema: {
74+
type: 'object',
75+
properties: {
76+
firstName: 'string'
77+
}
78+
},
79+
components: {
80+
"my-component": MyComponent
81+
},
82+
uiSchema: [{
83+
component: "my-component",
84+
model: 'firstName',
85+
fieldOptions: {
86+
on: ['input']
87+
}
88+
}]
89+
}
90+
}
91+
}
92+
</script>
93+
```

docs/api/vue-form-json-schema.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
| options | `Object` | See [Options](options.md) |
1010
| schema | `Object` | A valid [JSON Schema]( http://json-schema.org/) (validated by [Ajv](https://github.com/epoberezkin/ajv)) |
1111
| ui-schema | `Object` | See [uiSchema](ui-schema.md) |
12+
| components | `Object` | See [components](components.md) |
1213

1314
## Events
1415

@@ -26,6 +27,7 @@
2627
:options="options"
2728
:schema="schema"
2829
:ui-schema="uiSchema"
30+
:components="components"
2931
v-on:change="onModelUpdate"
3032
v-on:state-change="onStateUpdate"
3133
v-on:validated="onValidatedUpdate"

0 commit comments

Comments
 (0)