老莫的笔记本  
  
查看: 1081|回复: 0

React antd表单 从报错到放弃

[复制链接]

662

主题

878

帖子

5131

积分

超级版主

Rank: 8Rank: 8

积分
5131
发表于 2020-10-28 11:00:52 | 显示全部楼层 |阅读模式
本帖最后由 周大胖子 于 2020-10-28 14:55 编辑

先交代下环境:
react / umi / antd   且 react 使用了  createReactClass 的 写法

问题表像:
  那天 我要使用antd 的表单,然后 我就去复制官网上的表单源码[最简单的那种,然后 我就凉了 ,对的就这么直接 ]
Warning: React does not recognize the `valuePropName` prop on a DOM element.
好了,先说问题表象:由于太TM乱了 我决定放弃他 好了 写点简单的 ,把我放弃的代码放这,坐等下次继续
  1. //  商标搜索的 表单
  2. import React from 'react';
  3. import ReactDOM from 'react-dom';

  4. import { Form, Input, Button, Checkbox } from 'antd';

  5. const layout = {
  6.   // 这是结构
  7.   labelCol: {
  8.     span: 6,
  9.   },
  10.   wrapperCol: {
  11.     span: 18,
  12.   },
  13. };
  14. const tailLayout = {
  15.   wrapperCol: {
  16.     offset: 6,
  17.     span: 18,
  18.   },
  19. };

  20. const Demo = () => {
  21.   const onFinish = (values) => {
  22.     console.log('Success:', values);
  23.   };

  24.   const onFinishFailed = (errorInfo) => {
  25.     console.log('Failed:', errorInfo);
  26.   };

  27.   return (
  28.     <React.Fragment>
  29.     <div>
  30.     <Form
  31.       {...layout}
  32.       name="basic"
  33.       // initialValues={{
  34.       //   remember: true,
  35.       // }}
  36.       // onFinish={onFinish}
  37.       // onFinishFailed={onFinishFailed}
  38.     >

  39.       {/* 外围 form 表单直接报错 */}
  40.       {/* React does not recognize the `initialValues` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `initialvalues` instead. If you accidentally passed it from a parent component, remove it from the DOM element. */}
  41.       {/* 问题本质: react 关于在标签中 自定义属性[驼峰命名 且] 不被系统接受的问题 */}
  42.       

  43.       {/* 如果不要Form标签里面的自定义属性,不报错,但是下面报错:Cannot read property 'call' of undefined */}
  44.       <Form.Item
  45.         label="Username"
  46.         name="username"
  47.         rules={[
  48.           {
  49.             required: true,
  50.             message: 'Please input your username!',
  51.           },
  52.         ]}
  53.       >
  54.         <Input />
  55.       </Form.Item>

  56.       <Form.Item
  57.         label="Password"
  58.         name="password"
  59.         rules={[
  60.           {
  61.             required: true,
  62.             message: 'Please input your password!',
  63.           },
  64.         ]}
  65.       >
  66.         <Input.Password />
  67.       </Form.Item>

  68.       {/* 这一段加上,就会弹出警告React does not recognize the `valuePropName` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `valuepropname` instead. If you accidentally passed it from a parent component, remove it from the DOM element. */}
  69.       {/* 意思是 valuePropName 没有被识别 */}
  70.       {/* <Form.Item {...tailLayout} name="remember" valuePropName="checked">
  71.         <Checkbox>Remember me</Checkbox>
  72.       </Form.Item> */}

  73.       <Form.Item {...tailLayout}>
  74.         <Button type="primary" htmlType="submit">
  75.           Submit
  76.         </Button>
  77.       </Form.Item>



  78.     </Form>
  79.     </div>
  80.     </React.Fragment>
  81.   );
  82. };

  83. // ReactDOM.render(<Demo />, mountNode);
  84. export default Demo;
复制代码
  1. // 这是新闻的详情页  
  2. import React from 'react';
  3. import "../../assets/style/laomo.css";
  4. import createReactClass from 'create-react-class';
  5. import ReactDOM from 'react-dom';

  6. import Demo from './form';

  7. import { Row, Col, Divider } from 'antd';
  8. // const DemoBox = props => <p className={`height-${props.value}`}>{props.children}</p>;
  9. // import { Form, Input, Button, Select ,Checkbox  } from 'antd';


  10. // const Search = createReactClass({

  11. //     render(){
  12.   
  13. //         return (
  14. //             <section className="search-section">
  15. //                  这是商标查询页
  16. //                  <div className="search-box ">
  17. //                        
  18. //                         <div id="sm"></div>
  19. //                         {/* <Demo /> */}
  20. //                  </div>
  21. //             </section>
  22. //         );
  23. //     }

  24. // });
  25. // ReactDOM.render(<Demo />, document.getElementById("sm"));

  26. // ReactDOM.render(<Demo />, document.getElementById("sm"));
  27. // export default Search;


  28. class Search extends React.Component{
  29.         render(){
  30.   
  31.             return (
  32.                 <section className="search-section">
  33.                     <div className="search-box ">
  34.                         <Row justify="center" align="top" className="search-banner">
  35.                             <Col span={4}>
  36.                             </Col>
  37.                             <Col span={16} className="search-banner-form">
  38.                                 <Demo></Demo>
  39.                             </Col>
  40.                             <Col span={4}>
  41.                             </Col>
  42.                         </Row>
  43.                        
  44.                        
  45.                     </div>
  46.                 </section>
  47.             );
  48.         }
  49. }

  50. export default Search;


复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表