對(duì)input框賦值的時(shí)候监憎,報(bào)如下錯(cuò)誤:
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.
排查問題為組件還沒來得及創(chuàng)建鲸阔,就被賦值 所以找不到要被賦值的對(duì)象實(shí)例,故此報(bào)錯(cuò)褐筛。
解決辦法:在賦值之前添加一個(gè)延時(shí)操作叙身。
<a-input
id="copy"
v-="[
'value',
{rules: [{ required: true, message: 'XXX' }]}
]"
placeholder="eewew"
>
</a-input>
</a-form-item>
setTimeout(() => { // 添加延時(shí)操作
this.form1.setFieldsValue({ // form表單賦值
value: this.data
})
}, 100)
問題解決~~~~