@varlet/axle 0.2.7-alpha.1701536208987 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -87
- package/README.zh-CN.md +87 -87
- package/es/{chunk-KLNSLHAC.js → chunk-ZSUG26OQ.js} +1 -5
- package/es/index.d.ts +12 -4
- package/es/index.js +38 -10
- package/es/use.d.ts +0 -2
- package/es/use.js +1 -8
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -199,59 +199,58 @@ axle.removeHeader('TOKEN')
|
|
|
199
199
|
|
|
200
200
|
## Vue Composition API
|
|
201
201
|
|
|
202
|
-
Axle provides the usage of Vue Composition API style, which encapsulates the `loading status`, `error status`, `upload and download progress` of the request, `return data`, `
|
|
202
|
+
Axle provides the usage of Vue Composition API style, which encapsulates the `loading status`, `error status`, `upload and download progress` of the request, `return data`, `lifecycle`, etc., And inherit all the configuration of `axios`.
|
|
203
203
|
|
|
204
204
|
```html
|
|
205
205
|
<script setup>
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
})
|
|
206
|
+
import { createAxle } from '@varlet/axle'
|
|
207
|
+
import { createUseAxle } from '@varlet/axle/use'
|
|
208
|
+
|
|
209
|
+
const axle = createAxle(/** @see https://axios-http.com **/)
|
|
210
|
+
|
|
211
|
+
const useAxle = createUseAxle({
|
|
212
|
+
axle,
|
|
213
|
+
// Optional value: Default onTransform of the useAxle
|
|
214
|
+
onTransform: (response) => response,
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
const [users, getUsers, { loading, error, uploadProgress, downloadProgress, abort }] = useAxle({
|
|
218
|
+
// Request initial value
|
|
219
|
+
value: [],
|
|
220
|
+
// Request method
|
|
221
|
+
method: 'get',
|
|
222
|
+
// Request url
|
|
223
|
+
url: '/user',
|
|
224
|
+
// Whether to send the request immediately, defaults false
|
|
225
|
+
immediate: true,
|
|
226
|
+
// Whether the value needs to be reset before requesting, defaults false
|
|
227
|
+
resetValue: true,
|
|
228
|
+
// Request params, defaults {}
|
|
229
|
+
// When params is an object, it will be carried when sending the first request (immediate)
|
|
230
|
+
// When params is a function, it will be carried every time a request is sent.
|
|
231
|
+
params: { current: 1, pageSize: 10 },
|
|
232
|
+
// Axios config, see https://axios-http.com
|
|
233
|
+
config: { headers: {} },
|
|
234
|
+
// lifecycle
|
|
235
|
+
onBefore(refs) {
|
|
236
|
+
const { data, loading, error, uploadProgress, downloadProgress } = refs
|
|
237
|
+
console.log(data.value, loading.value, error.value, uploadProgress.value, downloadProgress.value)
|
|
238
|
+
// Do request before
|
|
239
|
+
},
|
|
240
|
+
onTransform(response, refs) {
|
|
241
|
+
// Handle data transform, The transformed data will be the value of users.
|
|
242
|
+
return response.data
|
|
243
|
+
},
|
|
244
|
+
onSuccess(response, refs) {
|
|
245
|
+
// Do request success
|
|
246
|
+
},
|
|
247
|
+
onError(error, refs) {
|
|
248
|
+
// Do request error
|
|
249
|
+
},
|
|
250
|
+
onAfter(refs) {
|
|
251
|
+
// Do request after
|
|
252
|
+
},
|
|
253
|
+
})
|
|
255
254
|
</script>
|
|
256
255
|
|
|
257
256
|
<template>
|
|
@@ -271,43 +270,44 @@ Axle provides some parallel request processing tools, please refer to the follow
|
|
|
271
270
|
|
|
272
271
|
```html
|
|
273
272
|
<script setup>
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
273
|
+
import { createAxle } from '@varlet/axle'
|
|
274
|
+
import { createUseAxle, useValues, useAverageProgress, useHasLoading } from '@varlet/axle/use'
|
|
275
|
+
|
|
276
|
+
const axle = createAxle(/** @see https://axios-http.com **/)
|
|
277
|
+
|
|
278
|
+
const useAxle = createUseAxle({ axle })
|
|
279
|
+
|
|
280
|
+
const [users, getUsers, { loading: isUsersLoading, downloadProgress: usersDownloadProgress }] = useAxle({
|
|
281
|
+
value: [],
|
|
282
|
+
method: 'get',
|
|
283
|
+
url: '/user',
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
const [roles, getRoles, { loading: isRolesLoading, downloadProgress: rolesDownloadProgress }] = useAxle({
|
|
287
|
+
value: [],
|
|
288
|
+
method: 'get',
|
|
289
|
+
url: '/role',
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
// At the end of all requests, loading is false
|
|
293
|
+
const loading = useHasLoading(isUsersLoading, isRolesLoading)
|
|
294
|
+
// At the end of all requests, downloadProgress is 1
|
|
295
|
+
const downloadProgress = useAverageProgress(usersDownloadProgress, rolesDownloadProgress)
|
|
296
|
+
// Ref<[
|
|
297
|
+
// [{ name: 'foo' }, { name: 'bar' }],
|
|
298
|
+
// [{ role: 'admin' }, { role: 'user' }]
|
|
299
|
+
// ]> <-
|
|
300
|
+
// [
|
|
301
|
+
// Ref<[{ name: 'foo' }, { name: 'bar' }]>,
|
|
302
|
+
// Ref<[{ role: 'admin' }, { role: 'user' }]>
|
|
303
|
+
// ]
|
|
304
|
+
const usersRoles = useValues(users, roles)
|
|
305
|
+
|
|
306
|
+
function sendAllRequest() {
|
|
307
|
+
// parallel
|
|
308
|
+
getUsers()
|
|
309
|
+
getRoles()
|
|
310
|
+
}
|
|
311
311
|
</script>
|
|
312
312
|
|
|
313
313
|
<template>
|
package/README.zh-CN.md
CHANGED
|
@@ -199,59 +199,58 @@ axle.removeHeader('TOKEN')
|
|
|
199
199
|
|
|
200
200
|
## Vue 组合式 API
|
|
201
201
|
|
|
202
|
-
Axle 提供了 Vue Composition API 风格的用法,封装了请求的 `加载状态`, `错误状态`,
|
|
202
|
+
Axle 提供了 Vue Composition API 风格的用法,封装了请求的 `加载状态`, `错误状态`, `请求的上下行进度`,`返回数据`,`生命周期` 等等,并继承了 `axios` 的所有配置。
|
|
203
203
|
|
|
204
204
|
```html
|
|
205
205
|
<script setup>
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
})
|
|
206
|
+
import { createAxle } from '@varlet/axle'
|
|
207
|
+
import { createUseAxle } from '@varlet/axle/use'
|
|
208
|
+
|
|
209
|
+
const axle = createAxle(/** @see https://axios-http.com **/)
|
|
210
|
+
|
|
211
|
+
const useAxle = createUseAxle({
|
|
212
|
+
axle,
|
|
213
|
+
// 可选项: useAxle 的默认 onTransform
|
|
214
|
+
onTransform: (response) => response,
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
const [users, getUsers, { loading, error, uploadProgress, downloadProgress, abort }] = useAxle({
|
|
218
|
+
// 请求初始化数据
|
|
219
|
+
value: [],
|
|
220
|
+
// 请求方法
|
|
221
|
+
method: 'get',
|
|
222
|
+
// 请求地址
|
|
223
|
+
url: '/user',
|
|
224
|
+
// 是否立即发送请求, 默认值: false
|
|
225
|
+
immediate: true,
|
|
226
|
+
// 请求前是否需要重置 value, 默认值: false
|
|
227
|
+
resetValue: true,
|
|
228
|
+
// 请求参数, 默认值: {}
|
|
229
|
+
// 当参数是一个对象时,发送第一个请求(immediate)时将携带它
|
|
230
|
+
// 当参数是一个函数时,每次发送请求时都会携带它。
|
|
231
|
+
params: { current: 1, pageSize: 10 },
|
|
232
|
+
// Axios 配置, see https://axios-http.com
|
|
233
|
+
config: { headers: {} },
|
|
234
|
+
// 生命周期
|
|
235
|
+
onBefore(refs) {
|
|
236
|
+
const { data, loading, error, uploadProgress, downloadProgress } = refs
|
|
237
|
+
console.log(data.value, loading.value, error.value, uploadProgress.value, downloadProgress.value)
|
|
238
|
+
// 处理请求前逻辑
|
|
239
|
+
},
|
|
240
|
+
onTransform(response, refs) {
|
|
241
|
+
// 处理数据转换,转换后的数据将成为 users 的值。
|
|
242
|
+
return response.data
|
|
243
|
+
},
|
|
244
|
+
onSuccess(response, refs) {
|
|
245
|
+
// 处理请求成功逻辑
|
|
246
|
+
},
|
|
247
|
+
onError(error, refs) {
|
|
248
|
+
// 处理请求错误逻辑
|
|
249
|
+
},
|
|
250
|
+
onAfter(refs) {
|
|
251
|
+
// 处理请求结束逻辑,无论成功失败都会触发。
|
|
252
|
+
},
|
|
253
|
+
})
|
|
255
254
|
</script>
|
|
256
255
|
|
|
257
256
|
<template>
|
|
@@ -271,43 +270,44 @@ Axle 提供了一些并行请求处理工具,请参考以下示例。
|
|
|
271
270
|
|
|
272
271
|
```html
|
|
273
272
|
<script setup>
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
273
|
+
import { createAxle } from '@varlet/axle'
|
|
274
|
+
import { createUseAxle, useValues, useAverageProgress, useHasLoading } from '@varlet/axle/use'
|
|
275
|
+
|
|
276
|
+
const axle = createAxle(/** @see https://axios-http.com **/)
|
|
277
|
+
|
|
278
|
+
const useAxle = createUseAxle({ axle })
|
|
279
|
+
|
|
280
|
+
const [users, getUsers, { loading: isUsersLoading, downloadProgress: usersDownloadProgress }] = useAxle({
|
|
281
|
+
value: [],
|
|
282
|
+
method: 'get',
|
|
283
|
+
url: '/user',
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
const [roles, getRoles, { loading: isRolesLoading, downloadProgress: rolesDownloadProgress }] = useAxle({
|
|
287
|
+
value: [],
|
|
288
|
+
method: 'get',
|
|
289
|
+
url: '/role',
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
// 所有请求结束时,loading 为 false
|
|
293
|
+
const loading = useHasLoading(isUsersLoading, isRolesLoading)
|
|
294
|
+
// 所有请求结束时,downloadProgress 为 1
|
|
295
|
+
const downloadProgress = useAverageProgress(usersDownloadProgress, rolesDownloadProgress)
|
|
296
|
+
// Ref<[
|
|
297
|
+
// [{ name: 'foo' }, { name: 'bar' }],
|
|
298
|
+
// [{ role: 'admin' }, { role: 'user' }]
|
|
299
|
+
// ]> <-
|
|
300
|
+
// [
|
|
301
|
+
// Ref<[{ name: 'foo' }, { name: 'bar' }]>,
|
|
302
|
+
// Ref<[{ role: 'admin' }, { role: 'user' }]>
|
|
303
|
+
// ]
|
|
304
|
+
const usersRoles = useValues(users, roles)
|
|
305
|
+
|
|
306
|
+
function sendAllRequest() {
|
|
307
|
+
// parallel
|
|
308
|
+
getUsers()
|
|
309
|
+
getRoles()
|
|
310
|
+
}
|
|
311
311
|
</script>
|
|
312
312
|
|
|
313
313
|
<template>
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
2
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
3
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
4
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -16,9 +14,7 @@ var __spreadValues = (a, b) => {
|
|
|
16
14
|
}
|
|
17
15
|
return a;
|
|
18
16
|
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
17
|
|
|
21
18
|
export {
|
|
22
|
-
__spreadValues
|
|
23
|
-
__spreadProps
|
|
19
|
+
__spreadValues
|
|
24
20
|
};
|
package/es/index.d.ts
CHANGED
|
@@ -4,26 +4,34 @@ import { AxiosInterceptorOptions, AxiosResponse } from 'axios';
|
|
|
4
4
|
|
|
5
5
|
interface RequestHeadersInterceptorOptions {
|
|
6
6
|
headers?: Record<string, string> | (() => Record<string, string>);
|
|
7
|
-
axiosInterceptorOptions?: AxiosInterceptorOptions;
|
|
8
7
|
include?: string[];
|
|
9
8
|
exclude?: string[];
|
|
9
|
+
axiosInterceptorOptions?: AxiosInterceptorOptions;
|
|
10
10
|
}
|
|
11
11
|
declare function requestHeadersInterceptor(options?: RequestHeadersInterceptorOptions): RequestInterceptor;
|
|
12
12
|
|
|
13
13
|
interface ResponseBlobInterceptorOptions {
|
|
14
14
|
onResponse?: (response: AxiosResponse<any, any>) => any;
|
|
15
|
-
axiosInterceptorOptions?: AxiosInterceptorOptions;
|
|
16
15
|
include?: string[];
|
|
17
16
|
exclude?: string[];
|
|
17
|
+
axiosInterceptorOptions?: AxiosInterceptorOptions;
|
|
18
18
|
}
|
|
19
19
|
declare function responseBlobInterceptor(options?: ResponseBlobInterceptorOptions): ResponseInterceptor;
|
|
20
20
|
|
|
21
21
|
interface ResponseTimeoutInterceptorOptions {
|
|
22
22
|
normalizeErrorCode?: string;
|
|
23
|
-
axiosInterceptorOptions?: AxiosInterceptorOptions;
|
|
24
23
|
include?: string[];
|
|
25
24
|
exclude?: string[];
|
|
25
|
+
axiosInterceptorOptions?: AxiosInterceptorOptions;
|
|
26
26
|
}
|
|
27
27
|
declare function responseTimeoutInterceptor(options?: ResponseTimeoutInterceptorOptions): ResponseInterceptor;
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
interface ResponseRetryInterceptorOptions {
|
|
30
|
+
count?: number;
|
|
31
|
+
include?: string[];
|
|
32
|
+
exclude?: string[];
|
|
33
|
+
axiosInterceptorOptions?: AxiosInterceptorOptions;
|
|
34
|
+
}
|
|
35
|
+
declare function responseRetryInterceptor(options: ResponseRetryInterceptorOptions): ResponseInterceptor;
|
|
36
|
+
|
|
37
|
+
export { RequestHeadersInterceptorOptions, RequestInterceptor, ResponseBlobInterceptorOptions, ResponseInterceptor, ResponseRetryInterceptorOptions, ResponseTimeoutInterceptorOptions, requestHeadersInterceptor, responseBlobInterceptor, responseRetryInterceptor, responseTimeoutInterceptor };
|
package/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__spreadValues
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZSUG26OQ.js";
|
|
4
4
|
|
|
5
5
|
// src/instance.ts
|
|
6
6
|
import axios from "axios";
|
|
@@ -155,9 +155,7 @@ function requestHeadersInterceptor(options = {}) {
|
|
|
155
155
|
});
|
|
156
156
|
return config;
|
|
157
157
|
},
|
|
158
|
-
onRejected(error)
|
|
159
|
-
return Promise.reject(error);
|
|
160
|
-
},
|
|
158
|
+
onRejected: (error) => Promise.reject(error),
|
|
161
159
|
options: options.axiosInterceptorOptions
|
|
162
160
|
};
|
|
163
161
|
}
|
|
@@ -176,9 +174,7 @@ function responseBlobInterceptor(options = {}) {
|
|
|
176
174
|
}
|
|
177
175
|
return response;
|
|
178
176
|
},
|
|
179
|
-
onRejected(error)
|
|
180
|
-
return Promise.reject(error);
|
|
181
|
-
},
|
|
177
|
+
onRejected: (error) => Promise.reject(error),
|
|
182
178
|
options: options.axiosInterceptorOptions
|
|
183
179
|
};
|
|
184
180
|
}
|
|
@@ -186,9 +182,7 @@ function responseBlobInterceptor(options = {}) {
|
|
|
186
182
|
// src/interceptors/responseTimeoutInterceptor.ts
|
|
187
183
|
function responseTimeoutInterceptor(options = {}) {
|
|
188
184
|
return {
|
|
189
|
-
onFulfilled(response)
|
|
190
|
-
return response;
|
|
191
|
-
},
|
|
185
|
+
onFulfilled: (response) => response,
|
|
192
186
|
onRejected(error) {
|
|
193
187
|
var _a, _b, _c;
|
|
194
188
|
const matcher = createMatcher(options.include, options.exclude);
|
|
@@ -203,6 +197,39 @@ function responseTimeoutInterceptor(options = {}) {
|
|
|
203
197
|
options: options.axiosInterceptorOptions
|
|
204
198
|
};
|
|
205
199
|
}
|
|
200
|
+
|
|
201
|
+
// src/interceptors/responseRetryInterceptor.ts
|
|
202
|
+
import axios2, { isCancel } from "axios";
|
|
203
|
+
function responseRetryInterceptor(options) {
|
|
204
|
+
return {
|
|
205
|
+
onFulfilled: (response) => response,
|
|
206
|
+
async onRejected(error) {
|
|
207
|
+
var _a, _b;
|
|
208
|
+
const matcher = createMatcher(options.include, options.exclude);
|
|
209
|
+
if (!matcher((_a = error.config.method) != null ? _a : "", (_b = error.config.url) != null ? _b : "")) {
|
|
210
|
+
return Promise.reject(error);
|
|
211
|
+
}
|
|
212
|
+
const { count = 1 } = options;
|
|
213
|
+
let retryCount = 0;
|
|
214
|
+
if (isCancel(error)) {
|
|
215
|
+
return Promise.reject(error);
|
|
216
|
+
}
|
|
217
|
+
async function loop() {
|
|
218
|
+
try {
|
|
219
|
+
retryCount++;
|
|
220
|
+
return await axios2.create()(error.config);
|
|
221
|
+
} catch (error2) {
|
|
222
|
+
if (retryCount === count) {
|
|
223
|
+
return Promise.reject(error2);
|
|
224
|
+
}
|
|
225
|
+
return loop();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return loop();
|
|
229
|
+
},
|
|
230
|
+
options: options.axiosInterceptorOptions
|
|
231
|
+
};
|
|
232
|
+
}
|
|
206
233
|
export {
|
|
207
234
|
createAxle,
|
|
208
235
|
createFetchRunner,
|
|
@@ -210,5 +237,6 @@ export {
|
|
|
210
237
|
download,
|
|
211
238
|
requestHeadersInterceptor,
|
|
212
239
|
responseBlobInterceptor,
|
|
240
|
+
responseRetryInterceptor,
|
|
213
241
|
responseTimeoutInterceptor
|
|
214
242
|
};
|
package/es/use.d.ts
CHANGED
|
@@ -13,7 +13,6 @@ interface RunOptions<P> {
|
|
|
13
13
|
params?: P;
|
|
14
14
|
config?: AxleRequestConfig;
|
|
15
15
|
resetValue?: boolean;
|
|
16
|
-
_retryCount?: number;
|
|
17
16
|
}
|
|
18
17
|
type Run<R, P> = (options?: RunOptions<P>) => Promise<R>;
|
|
19
18
|
interface UseAxleRefs<V> {
|
|
@@ -28,7 +27,6 @@ interface UseAxleOptions<V = any, R = any, P = Record<string, any>> {
|
|
|
28
27
|
method: RunnerMethod;
|
|
29
28
|
value?: V;
|
|
30
29
|
params?: P | (() => P);
|
|
31
|
-
retry?: number;
|
|
32
30
|
resetValue?: boolean;
|
|
33
31
|
config?: AxleRequestConfig;
|
|
34
32
|
immediate?: boolean;
|
package/es/use.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
__spreadProps,
|
|
3
2
|
__spreadValues
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZSUG26OQ.js";
|
|
5
4
|
|
|
6
5
|
// src/use.ts
|
|
7
6
|
import { ref as ref3 } from "vue";
|
|
@@ -61,7 +60,6 @@ function createUseAxle(options) {
|
|
|
61
60
|
resetValue: initialResetValue,
|
|
62
61
|
params: initialParamsOrGetter,
|
|
63
62
|
config: initialConfig,
|
|
64
|
-
retry = 0,
|
|
65
63
|
onBefore = () => {
|
|
66
64
|
},
|
|
67
65
|
onAfter = () => {
|
|
@@ -78,7 +76,6 @@ function createUseAxle(options) {
|
|
|
78
76
|
const error = ref3();
|
|
79
77
|
const downloadProgress = ref3(0);
|
|
80
78
|
const uploadProgress = ref3(0);
|
|
81
|
-
const shouldRetry = retry > 0;
|
|
82
79
|
const refs = {
|
|
83
80
|
value,
|
|
84
81
|
loading,
|
|
@@ -125,10 +122,6 @@ function createUseAxle(options) {
|
|
|
125
122
|
onAfter(refs);
|
|
126
123
|
return response;
|
|
127
124
|
} catch (responseError) {
|
|
128
|
-
const currentRetryCount = options3._retryCount == null ? 0 : options3._retryCount;
|
|
129
|
-
if (shouldRetry && currentRetryCount < retry) {
|
|
130
|
-
return run(__spreadProps(__spreadValues({}, options3), { _retryCount: currentRetryCount + 1 }));
|
|
131
|
-
}
|
|
132
125
|
error.value = responseError;
|
|
133
126
|
onError(responseError, refs);
|
|
134
127
|
loading.value = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/axle",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Progressive request tool based on axios",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "es/index.js",
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@varlet/shared": "^2.19.2",
|
|
43
43
|
"axios": "^1.4.0",
|
|
44
|
-
"micromatch": "^4.0.5",
|
|
45
44
|
"minimatch": "^9.0.3",
|
|
46
45
|
"qs": "^6.11.0"
|
|
47
46
|
},
|