繁体   English   中英

完全遵循以下示例后,无法使用antd FormItem

[英]Unable to use antd FormItem after following example exactly

完全遵循示例代码 我遇到了这个错误 在此处输入图片说明 只有当我排除使用FormItem包装输入时,错误才消失。 还有谁有相同的问题吗? 我完全遵循了代码。

使用antd@3.10.7 react@16.5.2

我的代码:从'react'导入React; 从“ antd”导入{表单,选择,输入,按钮};

const FormItem = Form.Item;
const Option = Select.Option;

class NewForm extends React.Component {
    constructor(props) {
        super(props);
        this.state = {};
    }

    handleSubmit = (e) => {
        e.preventDefault();
        this.props.form.validateFields((err, values) => {
          if (!err) {
            console.log('Received values of form: ', values);
          }
        });
      }

      handleSelectChange = (value) => {
        console.log(value);
        this.props.form.setFieldsValue({
          note: `Hi, ${value === 'male' ? 'man' : 'lady'}!`,
        });
      }

    render() {
        const { getFieldDecorator } = this.props.form;
        const hi = <Input />;
        console.log('hi', hi, typeof hi);
        return (
            <Form onSubmit={this.handleSubmit}>
                    <FormItem>
                        {getFieldDecorator('note', {
                    rules: [{ required: true, message: 'Please input your note!' }],
                    })(<Input />)}
                </FormItem>
                <FormItem>
                        {getFieldDecorator('gender', {
                        rules: [{ required: true, message: 'Please select your gender!' }],
                    })(
                        <Select
                        placeholder="Select a option and change input text above"
                        onChange={this.handleSelectChange}
                        >
                        <Option value="male">male</Option>
                        <Option value="female">female</Option>
                        </Select>
                    )}
                </FormItem>
                <FormItem >
                    <Button type="primary" htmlType="submit">
                        Submit
                    </Button>
                </FormItem>
            </Form>
        );
    }
}


export default Form.create()(NewForm);

我设法通过升级以下webpack模块来解决该错误。 希望它能帮助其他人。

旧的package.json

"@babel/cli": "7.0.0-beta.55",
"@babel/core": "7.0.0-beta.55",
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.55",
"@babel/plugin-proposal-export-default-from": "^7.0.0-beta.55",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.55",
"@babel/plugin-transform-arrow-functions": "^7.0.0-beta.55",
"@babel/plugin-transform-runtime": "7.0.0-beta.55",
"@babel/polyfill": "^7.0.0-beta.55",
"@babel/preset-env": "7.0.0-beta.55",
"@babel/preset-react": "7.0.0-beta.55",

新的package.json

"@babel/cli": "^7.1.5",
"@babel/core": "^7.1.5",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-transform-arrow-functions": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.1.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.1.5",
"@babel/preset-react": "^7.0.0",

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM