解决:You cannot set a form field before rendering a field associated with the value.

mac2025-07-27  1

> 使用antd的Form组件setFieldsValue可能会出现You cannot set a form field before rendering a field associated with the value.警告,字面意义去看是说在 render之前设置了表单值的问题。

那么怎么解决呢 1、在form组件显示出后,再用this.form.setFieldsValue 2、在this.$nextTick()中使用this.form.setFieldsValue 3、如果要表单绑定的数据和属性不匹配也会出现这个问题,这时就要使用第三种处理方法:在使用this.form.setFieldsValue时,赋值的数据要一一匹配field,用不到的不要赋值即可,这样操作之后错误提示就不再提醒了

综合以上三点,直接的解决办法为

visible = true; this.$nextTick(() => { this.form.setFieldsValue({ streamName: 'streamName', })});
最新回复(0)