hooks实例

import React, { useEffect, useState } from 'react';
import { useHistory,useLocation,useParams,useMatch } from 'react-router-dom';
import { Activeuser } from '@/services/sysuser';



  const history = useHistory();
  const [email , setEmail] = useState('');
  const [passwd , setPasswd] = useState('');

<Input placeholder="请输入邮箱地址" value={email} onChange={(e)=>{
          setEmail(e.target.value);
        }}/>
<Icon name="password-sharp" className="iconp"/>  <Input type="password" placeholder="请确认密码"  value={passwd} onChange={(e)=>{
          setPasswd(e.target.value);
        }}/>
        
  <Button type="primary" htmlType="submit" className={styles.submitBtn} onClick={async () => {
          Activeuser(email,passwd).then(result => {
            if(result.code==0){
                    history.push("/user/xxx");
            }else{
              message.error("失败")
            }
          });
        }}>


import request from '@/utils/request';
import { toFormatting } from '@/utils/util';

export interface InfoListParamsType{
  pageNo?: number;
  pageSize?: number;
}

export async function Activeuser(email?: string,passwd?: string) {
  return request('/api/user/xxx', {
     	method: 'POST',
        data: toFormatting({ email: email, passwd: passwd}),
  });
}

export async function GrantList(params:InfoListParamsType){
  return request('/api/user/xxx', {
        method: 'GET',
      params: toFormatting(params),
  });
}

export const toFormatting = (data: any): any => {
    for (let i in data) {
        let value = data[i];
        if (value === '' || value === null || value === undefined) {
            delete data[i];
        }
    }
    return data;
}
posted @ 2021-07-15 17:31  neverthelessing  阅读(63)  评论(0)    收藏  举报