zoukankan      html  css  js  c++  java
  • antd使用中遇到的问题

    基于antd 3.26.16版本中,使用hook,新增弹窗使用form表单遇到的问题

    1.首先导出时候需要加上Form.create

      正确:export default Form.create({name: 'sourceDialog'})(SourceDialog);

      错误:export default SourceDialog;

    2.在编写表单时,Radio组件设置defaultValue报错

    报错:Warning: `defaultValue` is invalid for `getFieldDecorator` will set `value`, please use `option.initialValue` instead.

      错误代码:

    <Form.Item label='模式'>
                            {getFieldDecorator('method', {
                                initialValue: sourceForm.method,
                                rules: [{required: true, message: '请选择模式'}],
                            })(
                                <Radio.Group defaultValue={sourceForm.method} onChange={(val) => {
                                    setSourceForm({
                                        ...setSourceForm,
                                        method: val,
                                    })
                                }}>
                                    {tableKeys.map((item) =>
                                        <Radio.Button value={item.name} key={item.key}>{item.name}</Radio.Button>
                                    )}
                                </Radio.Group>
                            )}
    </Form.Item>
    

      正确代码:

    <Form.Item label='模式'>
                            {getFieldDecorator('method', {
                                initialValue: sourceForm.method,
                                rules: [{required: true, message: '请选择模式'}],
                            })(
                                <Radio.Group onChange={(val) => {
                                    setSourceForm({
                                        ...setSourceForm,
                                        method: val,
                                    })
                                }}>
                                    {tableKeys.map((item) =>
                                        <Radio.Button value={item.name} key={item.key}>{item.name}</Radio.Button>
                                    )}
                                </Radio.Group>
                            )}
    </Form.Item>
    

     总结:Form.Item 子组件的 defaultValue 参数都要被 getFieldDecorator 中的 initialValue 替换。

     3.在组件Switch中设置报错

    报错:[antd: Switch] `value` is not validate prop, do you mean `checked`?

    错误代码:

    <Form.Item label='kerberos认证'>
                            {getFieldDecorator('kerberos', {
                                initialValue: sourceForm.kerberos,
    
                            })(
                                <Switch checkedChildren="是" unCheckedChildren="否" disabled={disabled} />
                            )}
    </Form.Item>

    正确代码:

    <Form.Item label='kerberos认证'>
                            {getFieldDecorator('kerberos', {
                                initialValue: sourceForm.kerberos,
                                valuePropName: 'checked'
                            })(
                                <Switch checkedChildren="是" unCheckedChildren="否" disabled={disabled} />
                            )}
    </Form.Item>
    

     总结:发现在getFieldDecorator包裹下的Switch组件无法显示为true的状态,Switch组件是通过checked的属性来显示状态的,所以需要一个额外的属性valuePropName

  • 相关阅读:
    UVaLive 3695 Distant Galaxy (扫描线)
    UVaLive 3695 City Game (扫描线)
    CodeForces 349B Color the Fence (DP)
    UVaLive 3905 Meteor (扫描线)
    UVaLive 3902 Network (无根树转有根树,贪心)
    NodeJS学习笔记 (16)子进程-child_process(ok)
    字符编码笔记:ASCII,Unicode 和 UTF-8
    NodeJS学习笔记 (15)二进制数据-buffer(ok)
    NodeJS学习笔记 (14)URL查询字符串-querystring(ok)
    NodeJS学习笔记 (13)数据加密-crypto(OK)
  • 原文地址:https://www.cnblogs.com/jiazhi88/p/12802953.html
Copyright © 2011-2022 走看看