chore: 新增put请求类型

This commit is contained in:
奔跑的面条 2022-05-28 00:40:22 +08:00
parent 15fc418fc4
commit c095e15d6c
2 changed files with 27 additions and 9 deletions

View File

@ -28,8 +28,6 @@ axiosInstance.interceptors.response.use(
return Promise.resolve(res.data) return Promise.resolve(res.data)
}, },
(err: AxiosResponse) => { (err: AxiosResponse) => {
const { code } = err.data as { code: number }
if (ErrorPageNameMap.get(code)) redirectErrorPage(code)
window['$message'].error('接口异常,请检查!') window['$message'].error('接口异常,请检查!')
Promise.reject(err) Promise.reject(err)
} }

View File

@ -19,6 +19,17 @@ export const post = (url: string, params: object, headersType?: string) => {
}) })
} }
export const put = (url: string, data?: object, headersType?: string) => {
return axiosInstance({
url: url,
method: RequestHttpEnum.PUT,
data: data,
headers: {
'Content-Type': headersType || ContentTypeEnum.JSON
}
})
}
export const del = (url: string, params: object) => { export const del = (url: string, params: object) => {
return axiosInstance({ return axiosInstance({
url: url, url: url,
@ -29,11 +40,20 @@ export const del = (url: string, params: object) => {
// 获取请求函数默认get // 获取请求函数默认get
export const http = (type?: RequestHttpEnum) => { export const http = (type?: RequestHttpEnum) => {
return type === RequestHttpEnum.GET switch (type) {
? get case RequestHttpEnum.GET:
: type === RequestHttpEnum.POST return get
? post
: type === RequestHttpEnum.DELETE case RequestHttpEnum.POST:
? del return post
: get
case RequestHttpEnum.PUT:
return put
case RequestHttpEnum.DELETE:
return del
default:
return get
}
} }