2024-05-03 19:16:54 +08:00
|
|
|
import { http, httpGet } from '@/utils/http'
|
|
|
|
export interface IFooItem {
|
|
|
|
id: string
|
|
|
|
name: string
|
|
|
|
}
|
2024-02-01 15:21:36 +08:00
|
|
|
|
2024-05-03 19:16:54 +08:00
|
|
|
/** GET 请求 */
|
2024-02-01 15:38:11 +08:00
|
|
|
export const getFooAPI = (name: string) => {
|
2024-02-01 15:35:41 +08:00
|
|
|
return http<IFooItem>({
|
2024-02-01 15:21:36 +08:00
|
|
|
url: `/foo`,
|
|
|
|
method: 'GET',
|
|
|
|
query: { name },
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-05-03 19:16:54 +08:00
|
|
|
/** GET 请求 - 再次简化,看大家是否喜欢这种简化 */
|
|
|
|
export const getFooAPI2 = (name: string) => {
|
|
|
|
return httpGet<IFooItem>('/foo', { name })
|
|
|
|
}
|
|
|
|
|
|
|
|
/** POST 请求 */
|
2024-02-01 15:38:11 +08:00
|
|
|
export const postFooAPI = (name: string) => {
|
2024-02-01 15:35:41 +08:00
|
|
|
return http<IFooItem>({
|
2024-02-01 15:21:36 +08:00
|
|
|
url: `/foo`,
|
|
|
|
method: 'POST',
|
|
|
|
query: { name }, // post 请求也支持 query
|
|
|
|
data: { name },
|
|
|
|
})
|
|
|
|
}
|