go-view/src/api/http.ts
2022-03-21 23:03:10 +08:00

40 lines
865 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import axiosInstance from './axios'
import { RequestHttpEnum, ContentTypeEnum } from '@/enums/httpEnum'
export const get = (url: string) => {
return axiosInstance({
url: url,
method: RequestHttpEnum.GET,
})
}
export const post = (url: string, params: object, headersType?: string) => {
return axiosInstance({
url: url,
method: RequestHttpEnum.POST,
data: params,
headers: {
'Content-Type': headersType || ContentTypeEnum.JSON
}
})
}
export const del = (url: string, params: object) => {
return axiosInstance({
url: url,
method: RequestHttpEnum.DELETE,
params
})
}
// 获取请求函数默认get
export const http = (type?: RequestHttpEnum) => {
return type === RequestHttpEnum.GET
? get
: type === RequestHttpEnum.POST
? post
: type === RequestHttpEnum.DELETE
? del
: get
}