对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.
排查问题为组件还没来得及创建,就被赋值 所以找不到要被赋值的对象实例,故此报错。
解决办法:在赋值之前添加一个延时操作。
<a-input
id="copy"
v-="[
'value',
{rules: [{ required: true, message: 'XXX' }]}
]"
placeholder="eewew"
>
</a-input>
</a-form-item>
setTimeout(() => { // 添加延时操作
this.form1.setFieldsValue({ // form表单赋值
value: this.data
})
}, 100)
问题解决~~~~