|
2 | 2 |
|
3 | 3 | **vue-dynamic-form-component** is a dynamic form component base on [element-ui](https://element.faas.ele.me/#/zh-CN) and [async-validator](https://github.com/yiminghe/async-validator). You just need to write **descriptors**(reference to [async-validator](https://github.com/yiminghe/async-validator)) of the data you want, **vue-dynamic-form-component** will generate the form automatically. |
4 | 4 |
|
| 5 | +## Usage |
| 6 | + |
| 7 | +``` vue |
| 8 | +<template> |
| 9 | + <dynamic-form |
| 10 | + ref="dynamic-form" |
| 11 | + v-model="data" |
| 12 | + :descriptors="descriptors"> |
| 13 | + <template slot="operations"> |
| 14 | + <el-button @click="reset">reset</el-button> |
| 15 | + <el-button type="primary" @click="validate">validate</el-button> |
| 16 | + </template> |
| 17 | + </dynamic-form> |
| 18 | +</template> |
| 19 | +
|
| 20 | +<script> |
| 21 | +// import and register element-ui first |
| 22 | +import DynamicForm from 'vue-dynamic-form-component' |
| 23 | +
|
| 24 | +export default { |
| 25 | + components: { |
| 26 | + DynamicForm |
| 27 | + }, |
| 28 | + data () { |
| 29 | + return { |
| 30 | + descriptors: { |
| 31 | + name: { type: 'string', min: 3, mex: 15, required: true }, |
| 32 | + homepage: { type: 'url', message: 'The homepage must be an url' }, |
| 33 | + company: { |
| 34 | + type: 'object', |
| 35 | + fields: { |
| 36 | + name: { type: 'string', required: true }, |
| 37 | + address: { |
| 38 | + type: 'object', |
| 39 | + fields: { |
| 40 | + province: { type: 'string', required: true }, |
| 41 | + city: { type: 'string' } |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + }, |
| 46 | + children: { |
| 47 | + type: 'array', |
| 48 | + defaultField: { |
| 49 | + type: 'object', |
| 50 | + fields:{ |
| 51 | + name: { type: 'string', min: 3, max: 15, required: true }, |
| 52 | + age: { type: 'number', min: 1, max: 100, required: true } |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + }, |
| 57 | + data: {} |
| 58 | + } |
| 59 | + }, |
| 60 | + methods: { |
| 61 | + reset () { |
| 62 | + this.$refs['dynamic-form'].resetFields() |
| 63 | + }, |
| 64 | + validate () { |
| 65 | + this.$refs['dynamic-form'].validate() |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | +</script> |
| 70 | +``` |
| 71 | + |
5 | 72 |  |
6 | 73 |
|
7 | 74 | ## Docs |
|
19 | 86 |
|
20 | 87 | ## Todo |
21 | 88 |
|
22 | | -vue-dynamic-form-component can do more. There are a few things that it currently doesn't support but are planned: |
| 89 | +**vue-dynamic-form-component** can do more. There are a few things that it currently doesn't support but are planned: |
23 | 90 |
|
24 | | -- Support more component |
25 | | -- Custom theme |
| 91 | +- [x] Custom component props |
| 92 | +- [ ] Custom component event |
| 93 | +- [ ] Support more component |
| 94 | + - [x] textarea |
| 95 | + - [ ] file upload |
| 96 | +- [ ] Custom theme |
| 97 | +- [ ] Value change event |
26 | 98 |
|
27 | 99 | ## Question |
28 | 100 |
|
|
0 commit comments