@axios-use/vue
Advanced tools
Comparing version 0.1.0-alpha.1 to 0.1.0-alpha.2
@@ -8,4 +8,4 @@ import { inject } from "vue"; | ||
export var getUseRequestConfig = function () { | ||
var _a = inject(AXIOS_USE_VUE_PROVIDE_KEY, {}).instance, instance = _a === void 0 ? axios : _a; | ||
var _a = (inject(AXIOS_USE_VUE_PROVIDE_KEY, {}) || {}).instance, instance = _a === void 0 ? axios : _a; | ||
return { instance: instance }; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import type { Ref } from "vue"; | ||
import type { ComputedRef, Ref } from "vue"; | ||
import type { AxiosResponse, Canceler } from "axios"; | ||
@@ -24,2 +24,2 @@ import type { RequestConfigType } from "./context"; | ||
}; | ||
export declare function useResource<T extends Request>(fn: T, requestParams?: FullRefArrayItem<Parameters<T>> | false, options?: UseResourceOptions<T>): UseResourceResult<T>; | ||
export declare function useResource<T extends Request>(fn: T, requestParams?: FullRefArrayItem<Parameters<T>> | ComputedRef<Parameters<T>> | false, options?: UseResourceOptions<T>): UseResourceResult<T>; |
@@ -1,2 +0,2 @@ | ||
import type { Ref } from "vue"; | ||
import type { ComputedRef, Ref } from "vue"; | ||
type Reducer<S, A> = (prevState: S, action: A) => S; | ||
@@ -22,3 +22,3 @@ type ReducerState<R extends Reducer<any, any>> = R extends Reducer<infer S, any> ? S : never; | ||
*/ | ||
export declare function unrefs<T extends any[]>(arr: FullRefArrayItem<T> | never[]): UnRefArrayItem<T>; | ||
export declare function unrefs<T extends any[]>(arr: FullRefArrayItem<T> | ComputedRef<T> | never[]): UnRefArrayItem<T>; | ||
export {}; |
@@ -15,5 +15,5 @@ "use strict"; | ||
var getUseRequestConfig = function () { | ||
var _a = (0, vue_1.inject)(exports.AXIOS_USE_VUE_PROVIDE_KEY, {}).instance, instance = _a === void 0 ? axios_1.default : _a; | ||
var _a = ((0, vue_1.inject)(exports.AXIOS_USE_VUE_PROVIDE_KEY, {}) || {}).instance, instance = _a === void 0 ? axios_1.default : _a; | ||
return { instance: instance }; | ||
}; | ||
exports.getUseRequestConfig = getUseRequestConfig; |
@@ -1,2 +0,2 @@ | ||
import type { Ref } from "vue"; | ||
import type { ComputedRef, Ref } from "vue"; | ||
import type { AxiosResponse, Canceler } from "axios"; | ||
@@ -24,2 +24,2 @@ import type { RequestConfigType } from "./context"; | ||
}; | ||
export declare function useResource<T extends Request>(fn: T, requestParams?: FullRefArrayItem<Parameters<T>> | false, options?: UseResourceOptions<T>): UseResourceResult<T>; | ||
export declare function useResource<T extends Request>(fn: T, requestParams?: FullRefArrayItem<Parameters<T>> | ComputedRef<Parameters<T>> | false, options?: UseResourceOptions<T>): UseResourceResult<T>; |
@@ -1,2 +0,2 @@ | ||
import type { Ref } from "vue"; | ||
import type { ComputedRef, Ref } from "vue"; | ||
type Reducer<S, A> = (prevState: S, action: A) => S; | ||
@@ -22,3 +22,3 @@ type ReducerState<R extends Reducer<any, any>> = R extends Reducer<infer S, any> ? S : never; | ||
*/ | ||
export declare function unrefs<T extends any[]>(arr: FullRefArrayItem<T> | never[]): UnRefArrayItem<T>; | ||
export declare function unrefs<T extends any[]>(arr: FullRefArrayItem<T> | ComputedRef<T> | never[]): UnRefArrayItem<T>; | ||
export {}; |
{ | ||
"name": "@axios-use/vue", | ||
"version": "0.1.0-alpha.1", | ||
"version": "0.1.0-alpha.2", | ||
"description": "A Vue composition utilities for Axios.", | ||
@@ -12,2 +12,4 @@ "main": "lib/index.js", | ||
"build:es": "tsc -m ESNext --outDir ./esm", | ||
"test": "vitest", | ||
"test:coverage": "vitest run --coverage", | ||
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --ignore-path .gitignore", | ||
@@ -40,2 +42,3 @@ "lint:fix": "yarn lint --fix", | ||
"@rushstack/eslint-patch": "^1.2.0", | ||
"@vitest/coverage-c8": "^0.29.2", | ||
"@vue/eslint-config-prettier": "^7.1.0", | ||
@@ -48,4 +51,5 @@ "@vue/eslint-config-typescript": "^11.0.2", | ||
"typescript": "^4.9.5", | ||
"vitest": "^0.29.2", | ||
"vue": "^3.2.47" | ||
} | ||
} |
@@ -45,7 +45,7 @@ <br> | ||
### Options | ||
### Options (optional) | ||
| config | type | explain | | ||
| -------- | ------ | -------------- | | ||
| instance | object | axios instance | | ||
| config | type | default | explain | | ||
| -------- | ------ | ------- | -------------- | | ||
| instance | object | `axios` | axios instance | | ||
@@ -210,2 +210,12 @@ ```ts | ||
// ComputedRef parameter | ||
const params = computed(() => ({ id: unref(userId) })); | ||
const [reqState, request] = useResource( | ||
({ id }) => ({ | ||
url: `/user/${id}`, | ||
method: "GET", | ||
}), | ||
[params], | ||
); | ||
// options: onCompleted, onError | ||
@@ -212,0 +222,0 @@ const [reqState] = useResource( |
47652
282
11