ant-design-vue/components/form/demo/without-form-create.vue

59 lines
1.5 KiB
Vue
Raw Normal View History

2018-05-07 10:40:25 +00:00
<cn>
#### 自行处理表单数据
使用 `Form.create` 处理后的表单具有自动收集数据并校验的功能但如果您不需要这个功能或者默认的行为无法满足业务需求可以选择不使用 `Form.create` 并自行处理数据
</cn>
<us>
#### Handle Form Data Manually
`Form.create` will collect and validate form data automatically. But if you don't need this feature or the default behaviour cannot satisfy your business, you can drop `Form.create` and handle form data manually.
</us>
<template>
<a-form>
<a-form-item
2019-02-01 09:23:00 +00:00
:label-col="labelCol"
:wrapper-col="wrapperCol"
2018-05-07 10:40:25 +00:00
label="Prime between 8 & 12"
2019-02-01 09:23:00 +00:00
:validate-status="number.validateStatus"
2018-05-07 10:40:25 +00:00
:help="number.errorMsg || tips"
>
2019-09-28 12:45:07 +00:00
<a-input-number :min="8" :max="12" :value="number.value" @change="handleNumberChange" />
2018-05-07 10:40:25 +00:00
</a-form-item>
</a-form>
</template>
<script>
2019-09-28 12:45:07 +00:00
function validatePrimeNumber(number) {
2018-05-07 10:40:25 +00:00
if (number === 11) {
return {
validateStatus: 'success',
errorMsg: null,
2019-01-12 03:33:27 +00:00
};
2018-05-07 10:40:25 +00:00
}
return {
validateStatus: 'error',
errorMsg: 'The prime between 8 and 12 is 11!',
2019-01-12 03:33:27 +00:00
};
2018-05-07 10:40:25 +00:00
}
export default {
2019-09-28 12:45:07 +00:00
data() {
2018-05-07 10:40:25 +00:00
return {
labelCol: { span: 7 },
wrapperCol: { span: 12 },
number: {
value: 11,
},
2019-09-28 12:45:07 +00:00
tips:
'A prime is a natural number greater than 1 that has no positive divisors other than 1 and itself.',
2019-01-12 03:33:27 +00:00
};
2018-05-07 10:40:25 +00:00
},
methods: {
2019-09-28 12:45:07 +00:00
handleNumberChange(value) {
2018-05-07 10:40:25 +00:00
this.number = {
...validatePrimeNumber(value),
value,
2019-01-12 03:33:27 +00:00
};
2018-05-07 10:40:25 +00:00
},
},
2019-01-12 03:33:27 +00:00
};
2018-05-07 10:40:25 +00:00
</script>