mirror of https://github.com/alibaba/ice.git
fix: request type (#151)
This commit is contained in:
parent
50981ba8fb
commit
719b22dcb5
|
|
@ -7,7 +7,8 @@ const Home = () => {
|
|||
|
||||
useEffect(() => {
|
||||
fetchRepo()
|
||||
|
||||
|
||||
request('/user').then(res => console.log('get:', res))
|
||||
// 2. requse.get alias
|
||||
request.get('/user').then(res => console.log('get:', res))
|
||||
|
||||
|
|
|
|||
|
|
@ -3,20 +3,21 @@ import * as utils from 'axios/lib/utils'
|
|||
import axiosInstance from './axiosInstance'
|
||||
|
||||
export interface IRequestProps {
|
||||
get?: (url: string, config?: AxiosRequestConfig) => Promise<AxiosResponse<any>>;
|
||||
delete?: (url: string, config?: AxiosRequestConfig) => Promise<AxiosResponse<any>>;
|
||||
head?: (url: string, config?: AxiosRequestConfig) => Promise<AxiosResponse<any>>;
|
||||
options?: (url: string, config?: AxiosRequestConfig) => Promise<AxiosResponse<any>>;
|
||||
post?: (url: string, data?: any, config?: AxiosRequestConfig) => Promise<AxiosResponse<any>>;
|
||||
put?: (url: string, data?: any, config?: AxiosRequestConfig) => Promise<AxiosResponse<any>>;
|
||||
patch?: (url: string, data?: any, config?: AxiosRequestConfig) => Promise<AxiosResponse<any>>;
|
||||
get: (url: string, config?: AxiosRequestConfig) => Promise<AxiosResponse<any>>;
|
||||
delete: (url: string, config?: AxiosRequestConfig) => Promise<AxiosResponse<any>>;
|
||||
head: (url: string, config?: AxiosRequestConfig) => Promise<AxiosResponse<any>>;
|
||||
options: (url: string, config?: AxiosRequestConfig) => Promise<AxiosResponse<any>>;
|
||||
post: (url: string, data?: any, config?: AxiosRequestConfig) => Promise<AxiosResponse<any>>;
|
||||
put: (url: string, data?: any, config?: AxiosRequestConfig) => Promise<AxiosResponse<any>>;
|
||||
patch: (url: string, data?: any, config?: AxiosRequestConfig) => Promise<AxiosResponse<any>>;
|
||||
}
|
||||
|
||||
interface IRequest extends IRequestProps {
|
||||
(options: AxiosRequestConfig): any;
|
||||
(url: string, config?: AxiosRequestConfig): any;
|
||||
}
|
||||
|
||||
const request: IRequest = async function (options: AxiosRequestConfig) {
|
||||
const request = async function (options) {
|
||||
try {
|
||||
const response = await axiosInstance(options)
|
||||
return response.data
|
||||
|
|
@ -46,4 +47,4 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
|||
};
|
||||
});
|
||||
|
||||
export default request
|
||||
export default request as IRequest
|
||||
|
|
|
|||
Loading…
Reference in New Issue