Commit 8d6029980538494979f0585dbd4823d1923cc6f8
1 parent
cf0e2f1a
Exists in
master
and in
1 other branch
feat: 优化form响应式
Showing
2 changed files
with
24 additions
and
7 deletions
Show diff stats
packages/form-item/index.vue
| ... | ... | @@ -6,12 +6,12 @@ export default { |
| 6 | 6 | labelWidth: String, |
| 7 | 7 | value: [Number, String, Array, Boolean, Object], |
| 8 | 8 | prop: String, |
| 9 | - span: { | |
| 10 | - type: [Number, String], | |
| 11 | - default() { | |
| 12 | - return this.zForm ? this.zForm.span : undefined; | |
| 13 | - }, | |
| 14 | - }, | |
| 9 | + span: [Number, String], | |
| 10 | + xs: [Number, Object], | |
| 11 | + sm: [Number, Object], | |
| 12 | + md: [Number, Object], | |
| 13 | + lg: [Number, Object], | |
| 14 | + xl: [Number, Object], | |
| 15 | 15 | }, |
| 16 | 16 | provide() { |
| 17 | 17 | return { |
| ... | ... | @@ -47,7 +47,7 @@ export default { |
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | - return h('el-col', { props: { span: this.span ? Number(this.span) : undefined } }, [ | |
| 50 | + return h('el-col', { props: this.colProps(['span', 'xs', 'sm', 'md', 'lg', 'xl']) }, [ | |
| 51 | 51 | h( |
| 52 | 52 | 'el-form-item', |
| 53 | 53 | { |
| ... | ... | @@ -58,5 +58,17 @@ export default { |
| 58 | 58 | ), |
| 59 | 59 | ]); |
| 60 | 60 | }, |
| 61 | + methods: { | |
| 62 | + colProps(props) { | |
| 63 | + return props.reduce((result, key) => { | |
| 64 | + if (this[key]) { | |
| 65 | + result[key] = this[key]; | |
| 66 | + } else { | |
| 67 | + result[key] = this.zForm ? this.zForm[key] : undefined; | |
| 68 | + } | |
| 69 | + return result; | |
| 70 | + }, {}); | |
| 71 | + }, | |
| 72 | + }, | |
| 61 | 73 | }; |
| 62 | 74 | </script> | ... | ... |
packages/form/index.vue