fix: 修复白屏的问题
parent
d173a4092a
commit
ac3c08ad7b
47
README.md
47
README.md
|
@ -183,28 +183,28 @@ axios.get(
|
||||||
|
|
||||||
非全平台兼容的属性只会在平台支持的情况下生效。
|
非全平台兼容的属性只会在平台支持的情况下生效。
|
||||||
|
|
||||||
| 参数 | 类型 | 默认值 | 说明 | 全平台兼容 |
|
| 参数 | 类型 | 默认值 | 说明 | 全平台兼容 |
|
||||||
| :---------------- | :------------------------ | :------------------------------------------------------------------------------------ | :----------------- | :--------- |
|
| :---------------- | :-----------------------: | :----------------------------------------------------------- | :----------------- | :--------- |
|
||||||
| adapter | Function | [查看](https://github.com/early-autumn/axios-miniprogram/blob/master/src/defaults.ts) | 自定义适配器 | 是 |
|
| adapter | Function | [查看](https://github.com/early-autumn/axios-miniprogram/blob/master/src/defaults.ts) | 自定义适配器 | 是 |
|
||||||
| baseURL | String | | 基础地址 | 是 |
|
| baseURL | String | | 基础地址 | 是 |
|
||||||
| url | String | | 请求地址 | 是 |
|
| url | String | | 请求地址 | 是 |
|
||||||
| method | String | get | 请求方法 | |
|
| method | String | get | 请求方法 | |
|
||||||
| params | Object | | 请求参数 | 是 |
|
| params | Object | | 请求参数 | 是 |
|
||||||
| data | String/Object/ArrayBuffer | | 请求数据 | 是 |
|
| data | String/Object/ArrayBuffer | | 请求数据 | 是 |
|
||||||
| headers | Object | [查看](https://github.com/early-autumn/axios-miniprogram/blob/master/src/defaults.ts) | 请求头 | 是 |
|
| 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) | 自定义合法状态码 | 是 |
|
| validateStatus | Function | [查看](https://github.com/early-autumn/axios-miniprogram/blob/master/src/defaults.ts) | 自定义合法状态码 | 是 |
|
||||||
| paramsSerializer | Function | | 自定义参数序列化 | 是 |
|
| paramsSerializer | Function | | 自定义参数序列化 | 是 |
|
||||||
| transformRequest | Function/Array<.Function> | | 自定义转换请求数据 | 是 |
|
| transformRequest | Function/Array<.Function> | | 自定义转换请求数据 | 是 |
|
||||||
| transformResponse | Function/Array<.Function> | | 自定义转换响应数据 | 是 |
|
| transformResponse | Function/Array<.Function> | | 自定义转换响应数据 | 是 |
|
||||||
| errorHandler | Function | | 自定义错误处理 | 是 |
|
| errorHandler | Function | | 自定义错误处理 | 是 |
|
||||||
| cancelToken | Object | | 取消令牌 | 是 |
|
| cancelToken | Object | | 取消令牌 | 是 |
|
||||||
| timeout | Number | 10000 | 超时时间 | |
|
| timeout | Number | 10000 | 超时时间 | |
|
||||||
| dataType | String | json | 响应数据格式 | 是 |
|
| dataType | String | json | 响应数据格式 | 是 |
|
||||||
| responseType | String | text | 响应数据类型 | 是 |
|
| responseType | String | text | 响应数据类型 | 是 |
|
||||||
| enableHttp2 | Boolean | false | 开启 http2 | |
|
| enableHttp2 | Boolean | false | 开启 http2 | |
|
||||||
| enableQuic | Boolean | false | 开启 quic | |
|
| enableQuic | Boolean | false | 开启 quic | |
|
||||||
| enableCache | Boolean | false | 开启 cache | |
|
| enableCache | Boolean | false | 开启 cache | |
|
||||||
| sslVerify | Boolean | true | 验证 ssl 证书 | |
|
| sslVerify | Boolean | true | 验证 ssl 证书 | |
|
||||||
|
|
||||||
#### `config.method`的合法值
|
#### `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
|
// axios => axios.interceptors.request => config.transformRequest => config.paramsSerializer => config.adapter => config.validateStatus => config.transformResponse => config.errorHandler => axios.interceptors.response => catch
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,15 +23,15 @@ export function buildURL(
|
||||||
return generateURL(url, paramsSerializer(params));
|
return generateURL(url, paramsSerializer(params));
|
||||||
}
|
}
|
||||||
|
|
||||||
const combineREG = /(?<!:)\/{2,}/g;
|
const combineREG = /([^:])\/{2,}/g;
|
||||||
export function combineURL(baseURL = '', url: string): string {
|
export function combineURL(baseURL = '', url: string): string {
|
||||||
const separator = '/';
|
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;
|
const dynamicREG = /\/?(:([a-zA-Z_$][\w-$]*))\/??/g;
|
||||||
|
|
||||||
export function dynamicInterpolation(url: string, sourceData?: any): string {
|
export function dynamicInterpolation(url: string, sourceData?: any): string {
|
||||||
if (!isPlainObject(sourceData)) {
|
if (!isPlainObject(sourceData)) {
|
||||||
return url;
|
return url;
|
||||||
|
@ -43,7 +43,6 @@ export function dynamicInterpolation(url: string, sourceData?: any): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
const absoluteREG = /^([a-z][a-z\d+\-.]*:)?\/\//i;
|
const absoluteREG = /^([a-z][a-z\d+\-.]*:)?\/\//i;
|
||||||
|
|
||||||
export function isAbsoluteURL(url: string): boolean {
|
export function isAbsoluteURL(url: string): boolean {
|
||||||
return absoluteREG.test(url);
|
return absoluteREG.test(url);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue