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)
},
(err: AxiosResponse) => {
const { code } = err.data as { code: number }
if (ErrorPageNameMap.get(code)) redirectErrorPage(code)
window['$message'].error('接口异常,请检查!')
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) => {
return axiosInstance({
url: url,
@ -29,11 +40,20 @@ export const del = (url: string, params: object) => {
// 获取请求函数默认get
export const http = (type?: RequestHttpEnum) => {
return type === RequestHttpEnum.GET
? get
: type === RequestHttpEnum.POST
? post
: type === RequestHttpEnum.DELETE
? del
: get
switch (type) {
case RequestHttpEnum.GET:
return get
case RequestHttpEnum.POST:
return post
case RequestHttpEnum.PUT:
return put
case RequestHttpEnum.DELETE:
return del
default:
return get
}
}