From dd6d80d1fe24d79f3146cbde727b24ae0971521c Mon Sep 17 00:00:00 2001 From: dpyzo0o Date: Mon, 30 Dec 2019 15:56:50 +0800 Subject: [PATCH] chore: tweak --- src/service/http.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/service/http.ts b/src/service/http.ts index 177e748..d6ae643 100644 --- a/src/service/http.ts +++ b/src/service/http.ts @@ -28,7 +28,7 @@ export interface IFetchOption { showErrorToast?: boolean; } -export interface IResponse { +export interface IResponse { /** * 后台定义的状态码 */ @@ -42,7 +42,7 @@ export interface IResponse { /** * 实际返回数据 */ - data?: any; + data?: T; } /** @@ -53,7 +53,7 @@ const CODE_SUCCESS = 200; Taro.addInterceptor(Taro.interceptors.logInterceptor); -async function fetch(option: IFetchOption) { +async function fetch(option: IFetchOption) { const { url, data, header, method, showErrorToast = true } = option; // 这里可以根据业务需求对 header 进行改造 @@ -62,7 +62,7 @@ async function fetch(option: IFetchOption) { * 根据后台实现做相应的修改, 小程序只要成功接收到服务器返回, 无论 statusCode 是多少 * 都会成功返回, 不会抛出错误, 所以需要根据后台实际返回的状态码来判断请求是否成功 */ - return Taro.request({ + return Taro.request>({ url, method, header, @@ -94,10 +94,10 @@ async function fetch(option: IFetchOption) { } export default { - get(option: IFetchOption) { - return fetch({ ...option, method: 'GET' }); + get(option: IFetchOption) { + return fetch({ ...option, method: 'GET' }); }, - post(option: IFetchOption) { - return fetch({ ...option, method: 'POST' }); + post(option: IFetchOption) { + return fetch({ ...option, method: 'POST' }); }, };