Skip to content

Commit

Permalink
feat(taro-h5): 设置 H5 端 Taro.request 保留 jsonp-retry 的参数
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Oct 24, 2018
1 parent dc86832 commit 0a2f975
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/taro-h5/src/api/request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export default function request (options) {
const params = {}
const res = {}
if (options.jsonp) {
Object.assign(params, options)
params.params = options.data
params.cache = options.jsonpCache
if (typeof options.jsonp === 'string') {
params.name = options.jsonp
}
delete params.jsonp
return jsonpRetry(url, params)
.then(data => {
res.statusCode = 200
Expand Down
52 changes: 45 additions & 7 deletions packages/taro/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ declare namespace Taro {
*/
method?: 'OPTIONS' | 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT'
/**
* 如果设为json,会尝试对返回的数据做一次 JSON.parse
* 如果设为 json,会尝试对返回的数据做一次 JSON.parse
*
* @default json
*/
Expand All @@ -495,35 +495,73 @@ declare namespace Taro {
*/
responseType?: string,
/**
* 设置H5端是否使用jsonp方式获取数据
* 设置 H5 端是否使用jsonp方式获取数据
*
* @default false
*/
jsonp?: boolean,
/**
* 设置H5端 jsonp 请求 url 是否需要被缓存
* 设置 H5 端 jsonp 请求 url 是否需要被缓存
*
* @default false
*/
jsonpCache?: boolean,
/**
* 设置H5端是否允许跨域请求。有效值:no-cors, cors, same-origin
* 设置 H5 端是否允许跨域请求。有效值:no-cors, cors, same-origin
*
* @default same-origin
*/
mode?: 'no-cors' | 'cors' | 'same-origin',
/**
* 设置H5端是否携带 Cookie。有效值:include, same-origin, omit
* 设置 H5 端是否携带 Cookie。有效值:include, same-origin, omit
*
* @default omit
*/
credentials?: 'include' | 'same-origin' | 'omit',
/**
* 设置H5端缓存模式。有效值:default, no-cache, reload, force-cache, only-if-cached
* 设置 H5 端缓存模式。有效值:default, no-cache, reload, force-cache, only-if-cached
*
* @default default
*/
cache?: 'default' | 'no-cache' | 'reload' | 'force-cache' | 'only-if-cached'
cache?: 'default' | 'no-cache' | 'reload' | 'force-cache' | 'only-if-cached',
/**
* 设置 H5 端请求响应超时时间
*
* @default 2000
*/
timeout?: number,
/**
* 设置 H5 端请求重试次数
*
* @default 2
*/
retryTimes?: number,
/**
* 设置 H5 端请求的兜底接口
*/
backup?: string | string[],
/**
* 设置 H5 端请求响应的数据校验函数,若返回 false,则请求兜底接口,若无兜底接口,则报请求失败
*/
dataCheck?(): boolean,
/**
* 设置 H5 端请求是否使用缓存
*
* @default false
*/
useStore: boolean,
/**
* 设置 H5 端请求缓存校验的 key
*/
storeCheckKey?: string,
/**
* 设置 H5 端请求缓存签名
*/
storeSign?: string,
/**
* 设置 H5 端请求校验函数,一般不需要设置
*/
storeCheck?(): boolean
}
}
/**
Expand Down

0 comments on commit 0a2f975

Please sign in to comment.