zoukankan      html  css  js  c++  java
  • ant design 表单的使用

    表单中有个重置表单的功能,

    这里有两种方式,hook组件和类组件,其本质是获取form的元素。

    在hook中获取元素应用方式如下:

     const [form] = Form.useForm();
    
    const onReset = () => {
        form.resetFields();
      };
    
      const onFill = () => {
        form.setFieldsValue({
          note: 'Hello world!',
          gender: 'male',
        });
      };
    
     <Form {...layout} form={form} name="control-hooks" onFinish={onFinish}>

    类组件中方式如下:

    class Demo extends React.Component {
      formRef = React.createRef();
    
     onReset = () => {
        this.formRef.current.resetFields();
      };
      onFill = () => {
        this.formRef.current.setFieldsValue({
          note: 'Hello world!',
          gender: 'male',
        });
      };

    <Form {...layout} ref={this.formRef} name="control-ref" onFinish={this.onFinish}> ...}

    主要分为三步:

    第一步,定义一个特殊对象来保存form元素

    第二步,获取form元素

    第三步,调用form元素的方法。

    至于有何不同,仔细研读上面代码。

    坚持下去就能成功
  • 相关阅读:
    JS中attribute和property的区别
    px(像素)、pt(点)、ppi、dpi、dp、sp之间的关系
    计算几何
    动态凸包
    斜率DP题目
    斜率DP个人理解
    后缀数组题目
    CF#190DIV.1
    MANACHER---求最长回文串
    扩展KMP题目
  • 原文地址:https://www.cnblogs.com/suoking/p/14722102.html
Copyright © 2011-2022 走看看