@varlet/axle 0.2.0 → 0.2.2

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 CHANGED
@@ -219,6 +219,8 @@ const [users, getUsers, { loading, error, uploadProgress, downloadProgress, abor
219
219
  // The number of retries after a failed request, defaults 0
220
220
  retry: 3,
221
221
  // Request params, defaults {}
222
+ // When params is an object, it will be carried when sending the first request (immediate)
223
+ // When params is a function, it will be carried every time a request is sent.
222
224
  params: { current: 1, pageSize: 10 },
223
225
  // Axios config, see https://axios-http.com
224
226
  config: { headers: {} },
package/README.zh-CN.md CHANGED
@@ -219,6 +219,8 @@ const [users, getUsers, { loading, error, uploadProgress, downloadProgress, abor
219
219
  // 错误重试次数, 默认值: 0
220
220
  retry: 3,
221
221
  // 请求参数, 默认值: {}
222
+ // 当参数是一个对象时,发送第一个请求(immediate)时将携带它
223
+ // 当参数是一个函数时,每次发送请求时都会携带它。
222
224
  params: { current: 1, pageSize: 10 },
223
225
  // Axios 配置, see https://axios-http.com
224
226
  config: { headers: {} },
package/es/use.d.ts CHANGED
@@ -18,7 +18,7 @@ export interface UseAxleOptions<V = any, R = any, P = Record<string, any>> {
18
18
  url: string;
19
19
  method: RunnerMethod;
20
20
  value?: V;
21
- params?: P;
21
+ params?: P | (() => P);
22
22
  retry?: number;
23
23
  config?: AxleRequestConfig;
24
24
  immediate?: boolean;
package/es/use.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { ref } from 'vue';
2
+ import { isFunction } from '@varlet/shared';
2
3
  export function createUseAxle(options) {
3
4
  const { axle, onTransform: defaultOnTransform } = options;
4
5
  const useAxle = (options) => {
5
6
  var _a;
6
- const { url, method, immediate, value: initialValue, params: initialParams, config: initialConfig, retry = 0, onBefore = () => { }, onAfter = () => { }, onTransform = (_a = defaultOnTransform) !== null && _a !== void 0 ? _a : ((response) => response), onSuccess = () => { }, onError = () => { }, } = options;
7
+ const { url, method, immediate, value: initialValue, params: initialParamsOrGetter, config: initialConfig, retry = 0, onBefore = () => { }, onAfter = () => { }, onTransform = (_a = defaultOnTransform) !== null && _a !== void 0 ? _a : ((response) => response), onSuccess = () => { }, onError = () => { }, } = options;
7
8
  const initialUrl = url;
8
9
  const value = ref(initialValue);
9
10
  const loading = ref(false);
@@ -30,7 +31,8 @@ export function createUseAxle(options) {
30
31
  onBefore(refs);
31
32
  loading.value = true;
32
33
  try {
33
- const response = await axle[method](url, options.params, Object.assign({ signal: controller.signal, onUploadProgress(event) {
34
+ const getterParams = isFunction(initialParamsOrGetter) ? initialParamsOrGetter() : {};
35
+ const response = await axle[method](url, Object.assign(Object.assign({}, getterParams), options.params), Object.assign({ signal: controller.signal, onUploadProgress(event) {
34
36
  var _a;
35
37
  uploadProgress.value = (_a = event.progress) !== null && _a !== void 0 ? _a : 0;
36
38
  },
@@ -63,7 +65,7 @@ export function createUseAxle(options) {
63
65
  if (immediate) {
64
66
  run({
65
67
  url: initialUrl,
66
- params: initialParams,
68
+ params: isFunction(initialParamsOrGetter) ? {} : initialParamsOrGetter,
67
69
  config: initialConfig,
68
70
  });
69
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/axle",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Progressive request tool based on axios",
5
5
  "type": "module",
6
6
  "main": "es/index.js",
@@ -29,13 +29,13 @@
29
29
  "author": "haoziqaq <357229046@qq.com>",
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
- "@varlet/shared": "^2.11.8",
32
+ "@varlet/shared": "^2.19.2",
33
33
  "axios": "^1.4.0",
34
34
  "qs": "^6.11.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/qs": "^6.9.7",
38
- "@varlet/cli": "^2.15.0",
38
+ "@varlet/release": "0.0.3",
39
39
  "rimraf": "^5.0.1",
40
40
  "typescript": "^5.1.5",
41
41
  "vue": "3.3.4"
@@ -47,7 +47,7 @@
47
47
  "bugs": {
48
48
  "url": "https://github.com/varletjs/axle/issues"
49
49
  },
50
- "packageManager": "pnpm@8.0.0",
50
+ "packageManager": "pnpm@8.7.5",
51
51
  "engines": {
52
52
  "pnpm": ">=8.0"
53
53
  },
@@ -55,6 +55,6 @@
55
55
  "bootstrap": "pnpm i && pnpm build && pnpm --filter ./playground i",
56
56
  "dev": "tsc -w",
57
57
  "build": "rimraf ./es && tsc",
58
- "release": "pnpm build && varlet-cli release"
58
+ "release": "pnpm build && vr release"
59
59
  }
60
60
  }