| San3yuan | 4d0e803 | 2025-04-04 17:21:40 +0800 | [diff] [blame^] | 1 | import React, { useEffect } from 'react'; |
| 2 | import { useApi } from '@/hooks/request'; |
| 3 | import request from '@/utils/request'; |
| 4 | import {userLogin} from '@/api/user'; |
| 5 | import { useAppDispatch } from '@/hooks/store'; |
| 6 | |
| 7 | const 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 | |
| 29 | export default Login; |