Merge pull request #32 from fluffff/dev

fix: 修复白屏的问题
pull/33/head
初秋 2021-06-30 22:48:37 +08:00 committed by GitHub
commit 981648817d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 26 deletions

View File

@ -183,28 +183,28 @@ axios.get(
非全平台兼容的属性只会在平台支持的情况下生效。
| 参数 | 类型 | 默认值 | 说明 | 全平台兼容 |
| :---------------- | :------------------------ | :------------------------------------------------------------------------------------ | :----------------- | :--------- |
| adapter | Function | [查看](https://github.com/early-autumn/axios-miniprogram/blob/master/src/defaults.ts) | 自定义适配器 | 是 |
| baseURL | String | | 基础地址 | 是 |
| url | String | | 请求地址 | 是 |
| method | String | get | 请求方法 | |
| params | Object | | 请求参数 | 是 |
| data | String/Object/ArrayBuffer | | 请求数据 | 是 |
| headers | Object | [查看](https://github.com/early-autumn/axios-miniprogram/blob/master/src/defaults.ts) | 请求头 | 是 |
| validateStatus | Function | [查看](https://github.com/early-autumn/axios-miniprogram/blob/master/src/defaults.ts) | 自定义合法状态码 | 是 |
| paramsSerializer | Function | | 自定义参数序列化 | 是 |
| transformRequest | Function/Array<.Function> | | 自定义转换请求数据 | 是 |
| transformResponse | Function/Array<.Function> | | 自定义转换响应数据 | 是 |
| errorHandler | Function | | 自定义错误处理 | 是 |
| cancelToken | Object | | 取消令牌 | 是 |
| timeout | Number | 10000 | 超时时间 | |
| dataType | String | json | 响应数据格式 | 是 |
| responseType | String | text | 响应数据类型 | 是 |
| enableHttp2 | Boolean | false | 开启 http2 | |
| enableQuic | Boolean | false | 开启 quic | |
| enableCache | Boolean | false | 开启 cache | |
| sslVerify | Boolean | true | 验证 ssl 证书 | |
| 参数 | 类型 | 默认值 | 说明 | 全平台兼容 |
| :---------------- | :-----------------------: | :----------------------------------------------------------- | :----------------- | :--------- |
| adapter | Function | [查看](https://github.com/early-autumn/axios-miniprogram/blob/master/src/defaults.ts) | 自定义适配器 | 是 |
| baseURL | String | | 基础地址 | 是 |
| url | String | | 请求地址 | 是 |
| method | String | get | 请求方法 | |
| params | Object | | 请求参数 | 是 |
| data | String/Object/ArrayBuffer | | 请求数据 | 是 |
| headers | Object | [查看](https://github.com/early-autumn/axios-miniprogram/blob/master/src/defaults.ts) | 请求头 | 是 |
| validateStatus | Function | [查看](https://github.com/early-autumn/axios-miniprogram/blob/master/src/defaults.ts) | 自定义合法状态码 | 是 |
| paramsSerializer | Function | | 自定义参数序列化 | 是 |
| transformRequest | Function/Array<.Function> | | 自定义转换请求数据 | 是 |
| transformResponse | Function/Array<.Function> | | 自定义转换响应数据 | 是 |
| errorHandler | Function | | 自定义错误处理 | 是 |
| cancelToken | Object | | 取消令牌 | 是 |
| timeout | Number | 10000 | 超时时间 | |
| dataType | String | json | 响应数据格式 | 是 |
| responseType | String | text | 响应数据类型 | 是 |
| enableHttp2 | Boolean | false | 开启 http2 | |
| enableQuic | Boolean | false | 开启 quic | |
| enableCache | Boolean | false | 开启 cache | |
| sslVerify | Boolean | true | 验证 ssl 证书 | |
#### `config.method`的合法值
@ -575,3 +575,6 @@ axios("/user")
// 请求失败
// axios => axios.interceptors.request => config.transformRequest => config.paramsSerializer => config.adapter => config.validateStatus => config.transformResponse => config.errorHandler => axios.interceptors.response => catch
```

View File

@ -23,15 +23,15 @@ export function buildURL(
return generateURL(url, paramsSerializer(params));
}
const combineREG = /(?<!:)\/{2,}/g;
const combineREG = /([^:])\/{2,}/g;
export function combineURL(baseURL = '', url: string): string {
const separator = '/';
const replaceStr = `$1${separator}`;
return `${baseURL}${separator}${url}`.replace(combineREG, separator);
return `${baseURL}${separator}${url}`.replace(combineREG, replaceStr);
}
const dynamicREG = /\/?(:([a-zA-Z_$][\w-$]*))\/??/g;
export function dynamicInterpolation(url: string, sourceData?: any): string {
if (!isPlainObject(sourceData)) {
return url;
@ -43,7 +43,6 @@ export function dynamicInterpolation(url: string, sourceData?: any): string {
}
const absoluteREG = /^([a-z][a-z\d+\-.]*:)?\/\//i;
export function isAbsoluteURL(url: string): boolean {
return absoluteREG.test(url);
}