Class: FetchServer

FetchServer

new FetchServer(url, options)

service/FetchServer.js, line 21

服务请求执行器

Name Type Default Description
url String

服务地址

options Object {} 可选

可选参数

Name Type Default Description
headers Object 可选

自定义请求头参数

requestInterceptor function 可选

所有请求发送前会触发的函数

responseInterceptor function 可选

所有请求发送后会触发的函数

requestTimeout Number 45000 可选

请求超时时间,默认45000ms,即45s

tokenKey String 'token' 可选

token名

tokenValue String 可选

token值

tokenAttachType TokenAttachType TokenAttachType.normal 可选

指定token附加到何处

Members

headersfunction

请求头参数

requestInterceptorfunction

所有请求发送前会触发的函数

requestTimeoutfunction

请求超时时间,默认45000ms,即45s

responseInterceptorfunction

所有请求发送后会触发的函数

tokenAttachTypefunction

指定token附加到何处

tokenKeyfunction

token名

tokenValuefunction

token值

urlString

服务基地址

Methods

destroy()

service/FetchServer.js, line 83

销毁对象方法

request(options){Promise|undefined}

service/FetchServer.js, line 88

向服务发送请求

Name Type Default Description
options Object {} 可选

参数

Name Type Default Description
method string 可选

请求方式,包括 "GET"、"POST"、"PUT"、"DELETE"

url string 可选

发送请求的地址

data String | Object 可选

发送到服务器的数据,适用于 "POST"/"PUT"

success function 可选

成功回调函数。

failure function 可选

失败回调函数。

withCredentials Boolean true 可选

是否携带cookie。

processData function 可选

处理数据的回调函数

extensionOptions Object {} 可选

请求对象的扩展属性,可以通过该属性传入发送请求额外需要的参数

Returns:
Type Description
Promise | undefined 请求结果