欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

react清空ant.design中表單內(nèi)容的方法實(shí)現(xiàn)

 更新時(shí)間:2023年12月04日 11:06:20   作者:IDIOT___IDIOT  
本文主要介紹了react清空ant.design中表單內(nèi)容的方法實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

關(guān)于清空ant.design 中表單內(nèi)容的方法

其實(shí)就兩個(gè)方法具體怎么清除一個(gè)一個(gè)試試就知道了

表單有兩個(gè)可能的屬性:

  • form
  • formRef

可以用他們綁定兩個(gè)用法在代碼部分定義:

  • form = useRef()
  • form = Form.useForm()

清空的方法:

  • form.current?.setFieldsValue({這里把你的值放進(jìn)來并且賦值空字符串就好})
  • form.setFieldsValue({這里把你的值放進(jìn)來并且賦值空字符串就好})

使用實(shí)例:

import {
  LockOutlined,
  UserOutlined,
} from '@ant-design/icons';
import {
  LoginFormPage,
  ProConfigProvider,
  ProFormText,
} from '@ant-design/pro-components';
import {Button, Form, message, Tabs, theme} from 'antd';
import { useState } from 'react';
import {userRegisterUsingPost} from "@/services/yuapi/userController";
import { history } from '@umijs/max';


const Page = () => {
  const formRef = Form.useForm()
  const [loginType, setLoginType] = useState('register');
  const { token } = theme.useToken();
  const registerUser = async (values:API.UserRegisterRequest) => {
    const res = await userRegisterUsingPost({
      ...values
    })
    if(res.data){
      message.success("注冊(cè)成功")
      history.push('/user/login')
    }else{
      message.error(res.message)
      formRef.current?.setFieldsValue({
        userAccount:"",
        userPassword:"",
        checkPassword:""
      })
    }
  }
  return (
    <div
      style={{
        backgroundColor: 'white',
        height: '100vh',
      }}
    >
      <LoginFormPage
        onFinish={registerUser}
        formRef={formRef}
        submitter={{ searchConfig: { submitText: '注冊(cè)', }}}
        backgroundImageUrl="https://mdn.alipayobjects.com/huamei_gcee1x/afts/img/A*y0ZTS6WLwvgAAAAAAAAAAAAADml6AQ/fmt.webp"
        logo="https://github.githubassets.com/images/modules/logos_page/Octocat.png"
        backgroundVideoUrl="https://gw.alipayobjects.com/v/huamei_gcee1x/afts/video/jXRBRK_VAwoAAAAAAAAAAAAAK4eUAQBr"
        title="API 接口注冊(cè)"
        containerStyle={{
          backgroundColor: 'rgba(0, 0, 0,0.65)',
          backdropFilter: 'blur(4px)',
        }}
        subTitle="全球最大的接口管理平臺(tái)"
        activityConfig={{
          style: {
            boxShadow: '0px 0px 8px rgba(0, 0, 0, 0.2)',
            color: token.colorTextHeading,
            borderRadius: 8,
            backgroundColor: 'rgba(255,255,255,0.25)',
            backdropFilter: 'blur(4px)',
          },
          title: '活動(dòng)標(biāo)題,可配置圖片',
          subTitle: '活動(dòng)介紹說明文字',
          action: (
            <Button
              size="large"
              style={{
                borderRadius: 20,
                background: token.colorBgElevated,
                color: token.colorPrimary,
                width: 120,
              }}
            >
              去看看
            </Button>
          ),
        }}
        actions={
          <div
            style={{
              display: 'flex',
              justifyContent: 'center',
              alignItems: 'center',
              flexDirection: 'column',
            }}
          >
          </div>
        }
      >
        <Tabs
          centered
          activeKey={loginType}
        >
          <Tabs.TabPane key={'register'} tab={'賬號(hào)密碼注冊(cè)'} />
        </Tabs>
        {loginType === 'register' && (
          <>
            <ProFormText
              name="userAccount"
              fieldProps={{
                size: 'large',
                prefix: (
                  <UserOutlined
                    style={{
                      color: token.colorText,
                    }}
                    className={'prefixIcon'}
                  />
                ),
              }}
              placeholder={'請(qǐng)輸入用戶名'}
              rules={[
                {
                  required: true,
                  message: '請(qǐng)輸入用戶名!',
                },
              ]}
            />
            <ProFormText.Password
              name="userPassword"
              fieldProps={{
                size: 'large',
                prefix: (
                  <LockOutlined
                    style={{
                      color: token.colorText,
                    }}
                    className={'prefixIcon'}
                  />
                ),
              }}
              placeholder={'請(qǐng)輸入密碼'}
              rules={[
                {
                  required: true,
                  message: '請(qǐng)輸入密碼!',
                },
              ]}
            />
            <ProFormText.Password
              name="checkPassword"
              fieldProps={{
                size: 'large',
                prefix: (
                  <LockOutlined
                    style={{
                      color: token.colorText,
                    }}
                    className={'prefixIcon'}
                  />
                ),
              }}
              placeholder={'請(qǐng)確認(rèn)輸入密碼'}
              rules={[
                {
                  required: true,
                  message: '請(qǐng)輸入密碼!',
                },
              ]}
            />
          </>
        )}
        <div
          style={{
            marginBlockEnd: 24,
          }}
        >
          <a
            style={{
              float: 'right',
            }}
          >
            去登陸
          </a>
        </div>
      </LoginFormPage>
    </div>
  );
};

export default () => {
  return (
    <ProConfigProvider dark>
      <Page />
    </ProConfigProvider>
  );
};

第二個(gè)實(shí)例:

import React, {useEffect, useRef, useState} from 'react';
import {Button, Checkbox, Form, FormInstance, Input, message} from 'antd';
import {updateInterfaceInfoUsingPost} from "@/services/yuapi/interfaceInfoController";
import {ProForm} from "@ant-design/pro-form";
import useForm = ProForm.useForm;


export type Props = {
  handleUpdateModalOpen?:any;
  actionRef?:any;
  record: API.InterfaceInfo;
}

const UpdateFrom: React.FC<Props> = (props) => {
  useEffect(
    ()=>{
      formRef.setFieldsValue(props.record);
    }
    , [props.record]
  )
  const [data,setData] = useState(props.record);
  const [formRef] = Form.useForm()
  const onFinish = async (values: any) => {
    values = {
      ...values,
      id : props.record?.id
    }
    const res = await updateInterfaceInfoUsingPost(values);
    if(res.code == 0){
      props.handleUpdateModalOpen(false);
      message.success("修改成功");
      props.actionRef.current.reload();
    }else{
      message.error(res.message);
    }
  };
  const onFinishFailed = (errorInfo: any) => {
    console.log('Failed:', errorInfo);
  };
  return (
    <Form
      name="更新接口"
      labelCol={{span: 8}}
      wrapperCol={{span: 16}}
      style={{maxWidth: 600}}
      onFinish={onFinish}
      onFinishFailed={onFinishFailed}
      autoComplete="off"
      form={formRef}
    >
      <Form.Item
      >
        <h1>接口更新</h1>
      </Form.Item>
      <Form.Item
        label="接口名稱"
        name="name"
        rules={[{required: true, message: '請(qǐng)輸入接口名稱'}]}
      >
        <Input/>
      </Form.Item>

      <Form.Item
        label="接口描述"
        name="description"
        rules={[{required: false, message: '請(qǐng)輸入接口描述'}]}
      >
        <Input/>
      </Form.Item>
      <Form.Item
        label="接口地址"
        name="url"
        rules={[{required: true, message: '請(qǐng)輸入接口地址'}]}
      >
        <Input/>
      </Form.Item>
      <Form.Item
        label="接口調(diào)用方法"
        name="method"
        rules={[{required: true, message: '請(qǐng)輸入接口調(diào)用方法'}]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="接口參數(shù)信息"
        name="requestParams"
        rules={[{required: false, message: '請(qǐng)輸入接口參數(shù)信息'}]}
      >
        <Input.TextArea  rows={5}/>
      </Form.Item>
      <Form.Item
        label="接口請(qǐng)求頭信息"
        name="requestHeader"
        rules={[{required: false, message: '請(qǐng)輸入接口請(qǐng)求頭信息'}]}
      >
        <Input.TextArea rows={5}/>
      </Form.Item>
      <Form.Item
        label="接口響應(yīng)頭信息"
        name="responseHeader"
        rules={[{required: false, message: ''}]}
      >
        <Input.TextArea rows={5}/>
      </Form.Item>
      <Form.Item
        label="接口狀態(tài)"
        name="status"
        rules={[{required: true, message: '請(qǐng)輸入接口狀態(tài)'}]}
      >
        <Input/>
      </Form.Item>


      <Form.Item wrapperCol={{offset: 8, span: 16}}>
        <Button type="primary" htmlType="submit">
          Submit
        </Button>
      </Form.Item>
    </Form>
  );
}
export default UpdateFrom;

到此這篇關(guān)于react清空ant.design中表單內(nèi)容的方法實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)react清空ant.design表單內(nèi)容內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

  • 圖文示例講解useState與useReducer性能區(qū)別

    圖文示例講解useState與useReducer性能區(qū)別

    這篇文章主要為大家介紹了useState與useReducer性能區(qū)別圖文示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-05-05
  • React useMemo與useCallabck有什么區(qū)別

    React useMemo與useCallabck有什么區(qū)別

    useCallback和useMemo是一樣的東西,只是入?yún)⒂兴煌瑄seCallback緩存的是回調(diào)函數(shù),如果依賴項(xiàng)沒有更新,就會(huì)使用緩存的回調(diào)函數(shù);useMemo緩存的是回調(diào)函數(shù)的return,如果依賴項(xiàng)沒有更新,就會(huì)使用緩存的return
    2022-12-12
  • react組件的創(chuàng)建與更新實(shí)現(xiàn)流程詳解

    react組件的創(chuàng)建與更新實(shí)現(xiàn)流程詳解

    React組件分為函數(shù)組件與class組件;函數(shù)組件是無狀態(tài)組件,class稱為類組件;函數(shù)組件只有props,沒有自己的私有數(shù)據(jù)和生命周期函數(shù);class組件有自己私有數(shù)據(jù)(this.state)和生命周期函數(shù)
    2022-10-10
  • React?Hooks useReducer?逃避deps組件渲染次數(shù)增加陷阱

    React?Hooks useReducer?逃避deps組件渲染次數(shù)增加陷阱

    這篇文章主要介紹了React?Hooks?之?useReducer?逃避deps后增加組件渲染次數(shù)的陷阱詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • React各種狀態(tài)管理器的解讀及使用方法

    React各種狀態(tài)管理器的解讀及使用方法

    這篇文章主要介紹了對(duì)于React各種狀態(tài)管理器的解讀,文中給大家提到了狀態(tài)管理器是如何使用的,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-12-12
  • React?18?如何更新?state?中的對(duì)象

    React?18?如何更新?state?中的對(duì)象

    state 中可以保存任意類型的JavaScript值,包括對(duì)象,但是,不應(yīng)該直接修改存放在 React state 中的對(duì)象,這篇文章主要介紹了React?18更新state中的對(duì)象,需要的朋友可以參考下
    2023-08-08
  • React 錯(cuò)誤邊界組件的處理

    React 錯(cuò)誤邊界組件的處理

    這篇文章主要介紹了React 錯(cuò)誤邊界組件的處理,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • 一文教你如何避免React中常見的8個(gè)錯(cuò)誤

    一文教你如何避免React中常見的8個(gè)錯(cuò)誤

    這篇文章主要來和大家一起分享在?React?開發(fā)中常見的一些錯(cuò)誤,以及如何避免這些錯(cuò)誤,理解這些問題背后的細(xì)節(jié),防止犯下類似的錯(cuò)誤,需要的可以參考下
    2023-12-12
  • React中嵌套組件與被嵌套組件的通信過程

    React中嵌套組件與被嵌套組件的通信過程

    這篇文章主要介紹了React中嵌套組件與被嵌套組件的通信過程,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-07-07
  • react 組件實(shí)現(xiàn)無縫輪播示例詳解

    react 組件實(shí)現(xiàn)無縫輪播示例詳解

    這篇文章主要為大家介紹了react 組件實(shí)現(xiàn)無縫輪播示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10

最新評(píng)論