对接后端
This commit is contained in:
parent
1e49191b9a
commit
2f51cc4641
|
@ -2,6 +2,30 @@ import request from '@/utils/request'
|
||||||
import type { ApiResponse, PageResult } from './types'
|
import type { ApiResponse, PageResult } from './types'
|
||||||
|
|
||||||
// 定义接口的请求参数类型
|
// 定义接口的请求参数类型
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关键点说明:
|
||||||
|
* 类型定义:
|
||||||
|
* 使用 interface 定义接口的请求参数和响应数据类型
|
||||||
|
* 使用 Partial<T> 表示部分可选的类型
|
||||||
|
* 使用联合类型定义枚举值,如 0 | 1
|
||||||
|
* 请求方法:
|
||||||
|
* request.get<T>() - GET请求
|
||||||
|
* request.post<T>() - POST请求
|
||||||
|
* request.put<T>() - PUT请求
|
||||||
|
* 泛型参数 T 用于定义响应数据的类型
|
||||||
|
* 错误处理:
|
||||||
|
* 使用 try/catch 捕获请求错误
|
||||||
|
* 统一的错误提示
|
||||||
|
* 文件上传:
|
||||||
|
* 使用 FormData 处理文件上传
|
||||||
|
* 设置正确的 Content-Type
|
||||||
|
* 类型推导:
|
||||||
|
* TypeScript 会自动推导 API 响应的类型
|
||||||
|
* 编辑器会提供代码提示和类型检查
|
||||||
|
*/
|
||||||
|
|
||||||
export interface LoginParams {
|
export interface LoginParams {
|
||||||
phone: string
|
phone: string
|
||||||
password: string
|
password: string
|
||||||
|
|
Loading…
Reference in New Issue