对input框赋值的时候,报如下错误
warning.js?4eb8:34 Warning: You cannot set a form field before rendering a field associated with the value. You can use getFieldDecorator(id, options)
instead v-decorator="[id, options]"
to register it before render.
查了一半天,感觉意思是组件还没来得及创建完,就被赋值了。
于是加了个延时就好了。
setTimeout(() => {
this.form1.setFieldsValue({
value: this.data
})
}, 100)
beforeCreate () {
this.form1 = this.$form.createForm(this, { name: 'copy' })
}
<a-form-item label="XX">
<a-input
id="copy"
v-decorator="[
'value',
{rules: [{ required: true, message: 'XXX' }]}
]"
placeholder="eewew"
>
</a-input>
</a-form-item>