Comments (3)
#44 可能有用,但作者还没发布,可能都忘了
from luch-request.
暂时用declare module解决了
declare module 'luch-request' {
export type HttpTask = UniApp.RequestTask | UniApp.UploadTask | UniApp.DownloadTask;
export type HttpRequestTask = UniApp.RequestTask;
export type HttpUploadTask = UniApp.UploadTask;
export type HttpDownloadTask = UniApp.DownloadTask;
export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "CONNECT" | "HEAD" | "OPTIONS" | "TRACE" | "UPLOAD" | "DOWNLOAD";
export type HttpRequestHeader = Record<string, string>;
export type HttpParams = Record<string, any>;
export type HttpData = Record<string, any>;
export type HttpResponseType = 'arraybuffer' | 'text';
export type HttpCustom = Record<string, any>;
export type HttpFileType = 'image' | 'video' | 'audio';
export type HttpFormData = Record<string, any>;
export type HttpResponseHeader = Record<string, string> & {
"set-cookie"?: string[]
};
export interface HttpRequestConfig<T = HttpTask> {
/** @desc 请求服务器接口地址 */
url?: string;
/** @desc 请求方式,默认为 GET */
method?: HttpMethod;
/** @desc 请求基地址 */
baseURL?: string;
/** @desc 请求头信息,不能设置 Referer,App、H5 端会自动带上 cookie,且 H5 端不可手动修改 */
header?: HttpRequestHeader;
/** @desc 请求查询参数,自动拼接为查询字符串 */
params?: HttpParams;
/** @desc 请求体参数 */
data?: HttpData;
/** @desc 超时时间,单位 ms,默认为 60000,仅 H5 (HBuilderX 2.9.9+)、APP (HBuilderX 2.9.9+)、微信小程序 (2.10.0)、支付宝小程序支持 */
timeout?: number;
/** @desc 跨域请求时是否携带凭证 (cookies),默认为 false,仅 H5 (HBuilderX 2.6.15+) 支持 */
withCredentials?: boolean;
/** @desc 设置响应的数据类型,支付宝小程序不支持 */
responseType?: HttpResponseType;
/** @desc 全局自定义验证器 */
validateStatus?: ((statusCode: number) => boolean) | null;
/** @desc 默认为 json,如果设为 json,会尝试对返回的数据做一次 JSON.parse */
dataType?: string;
/** @desc DNS 解析时是否优先使用 ipv4,默认为 false,仅 App-Android (HBuilderX 2.8.0+) 支持 */
firstIpv4?: boolean;
/** @desc 是否验证 SSL 证书,默认为 true,仅 App-Android (HBuilderX 2.3.3+) 支持 */
sslVerify?: boolean;
/** @desc 自定义参数 */
custom?: HttpCustom;
/** @desc 返回当前请求的 task 和 options,不要在这里修改 options */
getTask?: (task: T, options: HttpRequestConfig<T>) => void;
/** @desc 需要上传的文件列表,使用 files 时,filePath 和 name 不生效,仅支持 App、H5 (2.6.15+) */
files?: { name?: string; file?: File; uri: string; }[];
/** @desc 文件类型,仅支付宝小程序支持且为必填项 */
fileType?: HttpFileType;
/** @desc 要上传的文件对象,仅 H5 (2.6.15+) 支持 */
file?: File;
/** @desc 要上传文件资源的路径,使用 files 时,filePath 和 name 不生效 */
filePath?: string;
/** @desc 文件对应的 key,开发者在服务器端通过这个 key 可以获取到文件二进制内容,使用 files 时,filePath 和 name 不生效 */
name?: string;
/** @desc 请求中其他额外的 form data */
formData?: HttpFormData;
}
export interface HttpResponse<T = any, D = HttpTask> {
data: T;
statusCode: number;
header: HttpResponseHeader;
config: HttpRequestConfig<D>;
cookies: string[];
errMsg: string;
}
export interface HttpUploadResponse<T = any, D = HttpTask> {
data: T;
statusCode: number;
config: HttpRequestConfig<D>;
errMsg: string;
}
export interface HttpDownloadResponse extends HttpResponse {
tempFilePath: string;
}
export interface HttpError<T = any, D = HttpTask> {
data?: T;
statusCode?: number;
header?: HttpResponseHeader;
config: HttpRequestConfig<D>;
cookies?: string[];
errMsg: string;
}
export interface HttpPromise<T = any> extends Promise<HttpResponse<T>> {}
export interface HttpInterceptorManager<V, E = V> {
use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: E) => E | Promise<E>): void;
eject(id: number): void;
}
export abstract class HttpRequestAbstract {
constructor(config?: HttpRequestConfig);
interceptors: {
request: HttpInterceptorManager<HttpRequestConfig>;
response: HttpInterceptorManager<HttpResponse, HttpError>;
}
request<T = any, R = HttpResponse<T>, D = HttpRequestTask>(config: HttpRequestConfig<D>): Promise<R>;
get<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, config?: HttpRequestConfig<D>): Promise<R>;
delete<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, data?: HttpData, config?: HttpRequestConfig<D>): Promise<R>;
head<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, data?: HttpData, config?: HttpRequestConfig<D>): Promise<R>;
options<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, data?: HttpData, config?: HttpRequestConfig<D>): Promise<R>;
post<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, data?: HttpData, config?: HttpRequestConfig<D>): Promise<R>;
put<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, data?: HttpData, config?: HttpRequestConfig<D>): Promise<R>;
config: HttpRequestConfig;
setConfig<D = HttpTask>(onSend: (config: HttpRequestConfig<D>) => HttpRequestConfig<D>): void;
connect<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, data?: HttpData, config?: HttpRequestConfig<D>): Promise<R>;
trace<T = any, R = HttpResponse<T>, D = HttpRequestTask>(url: string, data?: HttpData, config?: HttpRequestConfig<D>): Promise<R>;
upload<T = any, R = HttpUploadResponse<T>, D = HttpUploadTask>(url: string, config?: HttpRequestConfig<D>): Promise<R>;
download<T = any, R = HttpDownloadResponse, D = HttpDownloadTask>(url: string, config?: HttpRequestConfig<D>): Promise<R>;
middleware<T = any, R = HttpResponse<T>, D = HttpTask>(config: HttpRequestConfig<D>): Promise<R>;
}
class HttpRequest extends HttpRequestAbstract {}
export default HttpRequest;
}
from luch-request.
可以用patch解决一下
from luch-request.
Related Issues (20)
- 在请求之前拦截中执行 return Promise.reject(config) 取消请求,network中没有,但该请求最终还是执行了then逻辑 HOT 2
- TypeError: Cannot read property 'indexOf' of undefined
- 请求参数类型 HOT 1
- 响应拦截器异常触发 HOT 6
- 请求中断问题
- 关于luch-request全平台通用的问题 HOT 1
- err TypeError: relativeURL.replace is not a function HOT 2
- 【BUG】当 baseURL 为空时,请求 url 开头为 https://,实际请求 url 会变成本地 + https:// HOT 1
- 支持http2请求吗, HOT 4
- 后台返回流下载ecxel 下出来的文件会提示损坏 HOT 10
- 文档建议更新,比如安装和使用方式 HOT 2
- dataType设置成string,返回数据还是json HOT 1
- interceptors.response.use 参数内的header有丢失 HOT 2
- luch-request支持快手小程序吗 HOT 3
- 支持vue3吗 HOT 1
- 请求头header加不上 HOT 1
- Uni的命名空间名字换了,UniApp -> UniNamespace HOT 2
- 有没有锁住请求或者是重试接口 HOT 1
- Feat: 希望增加lock和unlock方法,拦截请求
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from luch-request.