在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/C  HTML/ react 中使用表單時(shí) You cannot set field before

react 中使用表單時(shí) You cannot set field before registering it.

在react中使用,ant design 中的form 表單,在處理后臺(tái)返回的錯(cuò)誤信息時(shí),報(bào)出You cannot set field before registering it.錯(cuò)誤,雖然意思容易理解,但是解決困難?希望遇見相同問題的大神指點(diǎn)迷津。其中用到this.props.form.setFields導(dǎo)致出現(xiàn)的問題。

回答
編輯回答
真難過

render中的處理

render() {
    const {getFieldProps} = this.props.form;
    return (
        <List>
            <InputItem {...getFieldProps('username')}/>
            <InputItem {...getFieldProps('password')}/>
        </List>
    );
}

不在render中的話一般在componentDidMount中手動(dòng)設(shè)置

this.props.form.setFieldsValue({
username:'xxx',
password:'xxx'
})
2017年7月9日 19:48
編輯回答
瘋子范

可能是你設(shè)置了原本不存在的Field value,解決方案是去掉不存在的,或者添加type為hidden的input可查看官方issues

2017年2月20日 22:26
編輯回答
尤禮

我今天也報(bào)這個(gè)錯(cuò),最后發(fā)現(xiàn)是Modal框里面設(shè)置了 destroyOnClose={true},導(dǎo)致報(bào)錯(cuò)!

2018年6月8日 19:02
編輯回答
氕氘氚
this.props.form.setFields

只能用在render之后的生命周期函數(shù)里,因?yàn)閒ields是在render函數(shù)里注冊(cè)的

2017年8月10日 11:38