我正在使用ant-design-vue编写自定义验证表单组件
我更改了代码,使其与官方网站上显示的示例几乎相同,但仍得到警告,唯一的区别是示例使用模板定义子组件,但我使用单个vue文件
//parent component
...some other code
<a-form-item
label="account"
>
<ReceiverAccount
v-decorator="[
'receiverAccount',
{
initialValue: step.receiverAccount,
rules: [
{
required: true,
message: 'need account',
}
]
}
]"
/>
</a-form-item>
...some other code
//child component
<template>
<a-input-group compact>
<a-select
:value="type"
@change="handleTypeChange"
>
<a-select-option value="alipay">alipay</a-select-option>
<a-select-option value="bank">bank</a-select-option>
</a-select>
<a-input
:value="number"
@change="handleNumberChange"
/>
</a-input-group>
</template>
<script>
export default {
props: {
value: {
type: Object,
default: () => {}
}
},
data() {
const { type, number } = this.value
return {
type: type || 'alipay',
number: number || ''
}
},
watch: {
value(val = {}) {
this.type = val.type || 'alipay'
this.number = val.number || ''
}
},
methods: {
handleTypeChange(val) {
this.triggerChange({ val })
},
handleNumberChange(e) {
const number = parseInt(e.target.value || 0, 10)
if (isNaN(number)) {
return
}
this.triggerChange({ number })
},
triggerChange(changedValue) {
this.$emit('change', Object.assign({}, this.$data, changedValue))
}
}
}
</script>
我希望一切都很好,但实际上是我得到了警告:getFieldDecorator
将覆盖value
,所以请不要直接设置value and v-model
并使用{{ 1}}进行设置。'
我该如何解决?预先感谢
答案 0 :(得分:0)
由于我是ant-design-vue的新手,经过一天的研究,解决方案是将value转换为v-model并删除子组件中的value道具。
<template>
<a-input-group compact>
<a-select
v-model="type"
@change="handleTypeChange"
>
<a-select-option value="alipay">alipay</a-select-option>
<a-select-option value="bank">bank</a-select-option>
</a-select>
<a-input
v-model="number"
@change="handleNumberChange"
/>
</a-input-group>
</template>