一、概述
在 React 開發中,對於 class 組件進行表單綁定時,我們通常會使用 ‘antd’ 的 getFieldDecorator,但是在使用過程中,很多人會遇到 ‘getfielddecoratorisnotafun’ 的錯誤,這個錯誤是什麼意思呢?其實,這個錯誤是指 getFieldDecorator 這個函數不存在或未定義。
二、常見錯誤原因
下面介紹一些 getFieldDecorator 報錯的原因:
1. getFieldDecorator 必須和 Form.Item 一起使用
{`// 錯誤示例
import { Form, Input } from 'antd';
const MyForm = () => {
const { getFieldDecorator } = Form.useForm(); return (
{/* 需要在 Form.Item 中使用 getFieldDecorator */}
{getFieldDecorator('username')(<Input placeholder="請輸入用戶名" />)}
<Input placeholder="請輸入密碼" />
原創文章,作者:TDGIZ,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/360900.html