blob: 9c1abc24a52012003b81db3332d70398c5f51cda [file] [log] [blame]
San3yuan4d0e8032025-04-04 17:21:40 +08001import React, { useEffect } from 'react';
2import { useApi } from '@/hooks/request';
3import request from '@/utils/request';
4import {userLogin} from '@/api/user';
5import { useAppDispatch } from '@/hooks/store';
6
7const Login: React.FC = () => {
8
9 const dispatch = useAppDispatch();
10 const { data, loading, error, refresh } = useApi(() => request.post(userLogin), false);
11
12 const handleLogin = async () => {
13 // 点击时调用 execute 发起请求
14 const res = await refresh();
15 console.log(res);
16 // 请求完成后可以使用返回的数据进行分发
17 dispatch({ type: "user/login", payload: res });
18 };
19 return (
20 <div>
21 <input type='email'></input>
22 <input></input>
23 <button onClick={handleLogin}>Login</button>
24 <button>Register</button>
25 </div>
26 );
27}
28
29export default Login;