mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-10 00:55:07 +08:00
refactor: vue3 axios api ...
This commit is contained in:
@ -1,46 +1,48 @@
|
||||
// import { service } from '@/config/axios'
|
||||
import { service } from '@/config/axios'
|
||||
|
||||
// import { AxiosPromise } from 'axios'
|
||||
import { config } from '@/config/axios/config'
|
||||
|
||||
// import { config } from '@/config/axios/config'
|
||||
const { default_headers } = config
|
||||
|
||||
// const { default_headers } = config
|
||||
const request = (option: AxiosConfig) => {
|
||||
const { url, method, params, data, headersType, responseType } = option
|
||||
return service({
|
||||
url: url,
|
||||
method,
|
||||
params,
|
||||
data,
|
||||
responseType: responseType,
|
||||
headers: {
|
||||
'Content-Type': headersType || default_headers
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// const request = <T>(option: AxiosConfig): AxiosPromise<T> => {
|
||||
// const { url, method, params, data, headersType, responseType } = option
|
||||
// return service({
|
||||
// url: url,
|
||||
// method,
|
||||
// params,
|
||||
// data,
|
||||
// responseType: responseType,
|
||||
// headers: {
|
||||
// 'Content-Type': headersType || default_headers
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
async function getFn<T = any>(option: AxiosConfig): Promise<T> {
|
||||
const res = await request({ method: 'GET', ...option })
|
||||
return res.data
|
||||
}
|
||||
|
||||
// function getFn<T = any>(option: AxiosConfig): AxiosPromise<T> {
|
||||
// return request<T>({ method: 'get', ...option })
|
||||
// }
|
||||
async function postFn<T = any>(option: AxiosConfig): Promise<T> {
|
||||
const res = await request({ method: 'POST', ...option })
|
||||
return res.data
|
||||
}
|
||||
|
||||
// function postFn<T = any>(option: AxiosConfig): AxiosPromise<T> {
|
||||
// return request<T>({ method: 'post', ...option })
|
||||
// }
|
||||
async function deleteFn<T = any>(option: AxiosConfig): Promise<T> {
|
||||
const res = await request({ method: 'DELETE', ...option })
|
||||
return res.data
|
||||
}
|
||||
|
||||
// function deleteFn<T = any>(option: AxiosConfig): AxiosPromise<T> {
|
||||
// return request<T>({ method: 'delete', ...option })
|
||||
// }
|
||||
async function putFn<T = any>(option: AxiosConfig): Promise<T> {
|
||||
const res = await request({ method: 'PUT', ...option })
|
||||
return res.data
|
||||
}
|
||||
|
||||
// function putFn<T = any>(option: AxiosConfig): AxiosPromise<T> {
|
||||
// return request<T>({ method: 'put', ...option })
|
||||
// }
|
||||
|
||||
// export const useAxios = () => {
|
||||
// return {
|
||||
// get: getFn,
|
||||
// post: postFn,
|
||||
// delete: deleteFn,
|
||||
// put: putFn
|
||||
// }
|
||||
// }
|
||||
export const useAxios = () => {
|
||||
return {
|
||||
get: getFn,
|
||||
post: postFn,
|
||||
delete: deleteFn,
|
||||
put: putFn
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user