Antd for Vue使用Form组件报错You cannot set a form field before rendering

时间:2022-07-22
本文章向大家介绍Antd for Vue使用Form组件报错You cannot set a form field before rendering,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

使用 Antd for Vue 的 setFieldsValue 赋值时报错: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.

报错的场景:

页面编辑时,获取接口数据,进行回显。

使用 setFieldsValue 给 v-decorator 赋值时报错。

this.form.setFieldsValue({ //数据回显
  id: res.data.result.id,
  linkPhone: res.data.result.linkPhone,
});

报错的原因:

this.form.setFieldsValue 传值的时候只能是 form 中用到的参数(即是 getFieldDecorator 方法中的 field )没有的 field 一律不允许多传,否则就会报错。

这里,多传递了多余的字段,自己检查一下,看看是否传递了页面中没有的字段。

本文已加入 腾讯云自媒体分享计划 (点击加入)

(adsbygoogle = window.adsbygoogle || []).push({});