ant-design-vue/components/form/demo/layout.vue

87 lines
2.0 KiB
Vue
Raw Normal View History

2018-05-06 18:32:40 +08:00
<cn>
#### 表单布局
表单有三种布局
</cn>
<us>
#### Form Layout
There are three layout for form: `horizontal`, `vertical`, `inline`.
</us>
<template>
2019-02-01 17:23:00 +08:00
<div>
<a-form :layout="formLayout">
<a-form-item
label="Form Layout"
:label-col="formItemLayout.labelCol"
:wrapper-col="formItemLayout.wrapperCol"
>
2019-09-28 20:45:07 +08:00
<a-radio-group default-value="horizontal" @change="handleFormLayoutChange">
2019-02-01 17:23:00 +08:00
<a-radio-button value="horizontal">
Horizontal
</a-radio-button>
<a-radio-button value="vertical">
Vertical
</a-radio-button>
<a-radio-button value="inline">
Inline
</a-radio-button>
</a-radio-group>
</a-form-item>
<a-form-item
label="Field A"
:label-col="formItemLayout.labelCol"
:wrapper-col="formItemLayout.wrapperCol"
>
<a-input placeholder="input placeholder" />
</a-form-item>
<a-form-item
label="Field B"
:label-col="formItemLayout.labelCol"
:wrapper-col="formItemLayout.wrapperCol"
>
<a-input placeholder="input placeholder" />
</a-form-item>
2019-09-28 20:45:07 +08:00
<a-form-item :wrapper-col="buttonItemLayout.wrapperCol">
2019-02-01 17:23:00 +08:00
<a-button type="primary">
Submit
</a-button>
</a-form-item>
</a-form>
</div>
2018-05-06 18:32:40 +08:00
</template>
<script>
export default {
2019-09-28 20:45:07 +08:00
data() {
2018-05-06 18:32:40 +08:00
return {
formLayout: 'horizontal',
2019-01-12 11:33:27 +08:00
};
2018-05-06 18:32:40 +08:00
},
computed: {
2019-09-28 20:45:07 +08:00
formItemLayout() {
2019-01-12 11:33:27 +08:00
const { formLayout } = this;
2019-09-28 20:45:07 +08:00
return formLayout === 'horizontal'
? {
labelCol: { span: 4 },
wrapperCol: { span: 14 },
}
: {};
2018-05-06 18:32:40 +08:00
},
2019-09-28 20:45:07 +08:00
buttonItemLayout() {
2019-01-12 11:33:27 +08:00
const { formLayout } = this;
2019-09-28 20:45:07 +08:00
return formLayout === 'horizontal'
? {
wrapperCol: { span: 14, offset: 4 },
}
: {};
2018-05-06 18:32:40 +08:00
},
},
2019-02-01 17:23:00 +08:00
methods: {
2019-09-28 20:45:07 +08:00
handleFormLayoutChange(e) {
2019-02-01 17:23:00 +08:00
this.formLayout = e.target.value;
},
},
2019-01-12 11:33:27 +08:00
};
2018-05-06 18:32:40 +08:00
</script>