Antd form和modal共同使用使用时 报错Warning:Instance created by `useForm` is not connect to any Form element

为何在 Modal 中调用 form 控制台会报错?

Warning: Instance created by useForm is not connect to any Form element. Forget to pass form prop?
在这里插入图片描述
这是因为你在调用 form 方法时,Modal 还未初始化导致 form 没有关联任何 Form 组件。你可以通过给 Modal 设置 forceRender 将其预渲染。
form需要设置form={form}

在这里插入图片描述

初始化form表单数据

const [form] = Form.useForm()
form.setFieldsValue(初始化数据)

猜你喜欢

转载自blog.csdn.net/weixin_47541876/article/details/125291484