You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
734 B
TypeScript
38 lines
734 B
TypeScript
|
4 years ago
|
import { service } from '@/plugins/axios'
|
||
|
|
|
||
|
|
import { AxiosPromise } from 'axios'
|
||
|
|
|
||
|
|
import { useAppStoreWithOut } from '@/store/modules/app'
|
||
|
|
|
||
|
|
import { config } from '@/config/axios'
|
||
|
|
|
||
|
|
const appStore = useAppStoreWithOut()
|
||
|
|
|
||
|
|
const { default_headers } = config
|
||
|
|
|
||
|
|
export function useAxios() {
|
||
|
|
function request({
|
||
|
|
url,
|
||
|
|
method,
|
||
|
|
params,
|
||
|
|
data,
|
||
|
|
headersType,
|
||
|
|
responseType
|
||
|
|
}: AxiosConfig): AxiosPromise {
|
||
|
|
return service({
|
||
|
|
url: url,
|
||
|
|
method,
|
||
|
|
params: appStore.getRequestTime ? { time: new Date().getTime(), ...(params || {}) } : params,
|
||
|
|
data,
|
||
|
|
responseType: responseType,
|
||
|
|
headers: {
|
||
|
|
'Content-Type': headersType || default_headers
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
return {
|
||
|
|
request
|
||
|
|
}
|
||
|
|
}
|