feat: axios 改造

This commit is contained in:
hongxinzz
2023-04-28 17:50:58 +08:00
parent 89844e441d
commit 5807db1dc1
4 changed files with 198 additions and 112 deletions

View File

@@ -1,33 +1,37 @@
import { service } from './service'
// import { service } from './service'
import { config } from './config'
// import { RequestConfig } from "./config"
const { default_headers } = config
// import { config } from './config'
const request = (option: any) => {
const { url, method, params, data, headersType, responseType } = option
return service({
url: url,
method,
params,
data,
responseType: responseType,
headers: {
'Content-Type': headersType || default_headers
}
})
}
export default {
get: <T = any>(option: any) => {
return request({ method: 'get', ...option }) as unknown as T
},
post: <T = any>(option: any) => {
return request({ method: 'post', ...option }) as unknown as T
},
delete: <T = any>(option: any) => {
return request({ method: 'delete', ...option }) as unknown as T
},
put: <T = any>(option: any) => {
return request({ method: 'put', ...option }) as unknown as T
}
}
// const { default_headers } = config
// const request = (option: any) => {
// const { url, method, params, data, headersType, responseType } = option
// return service({
// url: url,
// method,
// params,
// data,
// responseType: responseType,
// headers: {
// 'Content-Type': headersType || default_headers
// }
// })
// }
// export default {
// get: <T = any>(option: any) => {
// return request({ method: 'get', ...option }) as unknown as T
// },
// post: <T = any>(option: any) => {
// return request({ method: 'post', ...option }) as unknown as T
// },
// delete: <T = any>(option: any) => {
// return request({ method: 'delete', ...option }) as unknown as T
// },
// put: <T = any>(option: any) => {
// return request({ method: 'put', ...option }) as unknown as T
// }
// }
export {}