@vueuse/integrations 8.0.0-beta.3 → 8.0.0
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/index.cjs +23 -13
- package/index.d.ts +35 -9
- package/index.iife.js +23 -13
- package/index.iife.min.js +1 -1
- package/index.mjs +23 -13
- package/package.json +11 -11
- package/useAxios.cjs +23 -13
- package/useAxios.d.ts +35 -9
- package/useAxios.iife.js +23 -13
- package/useAxios.iife.min.js +1 -1
- package/useAxios.mjs +23 -13
package/index.cjs
CHANGED
|
@@ -43,21 +43,23 @@ var __spreadValues$3 = (a, b) => {
|
|
|
43
43
|
return a;
|
|
44
44
|
};
|
|
45
45
|
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
46
|
-
function useAxios(
|
|
46
|
+
function useAxios(...args) {
|
|
47
|
+
const url = typeof args[0] === "string" ? args[0] : void 0;
|
|
48
|
+
const argsPlaceholder = url ? 1 : 0;
|
|
47
49
|
let defaultConfig = {};
|
|
48
50
|
let instance = axios__default["default"];
|
|
49
|
-
let options = { immediate:
|
|
50
|
-
if (args.length > 0) {
|
|
51
|
-
if ("request" in args[0])
|
|
52
|
-
instance = args[0];
|
|
51
|
+
let options = { immediate: !!argsPlaceholder };
|
|
52
|
+
if (args.length > 0 + argsPlaceholder) {
|
|
53
|
+
if ("request" in args[0 + argsPlaceholder])
|
|
54
|
+
instance = args[0 + argsPlaceholder];
|
|
53
55
|
else
|
|
54
|
-
defaultConfig = args[0];
|
|
56
|
+
defaultConfig = args[0 + argsPlaceholder];
|
|
55
57
|
}
|
|
56
|
-
if (args.length > 1) {
|
|
57
|
-
if ("request" in args[1])
|
|
58
|
-
instance = args[1];
|
|
58
|
+
if (args.length > 1 + argsPlaceholder) {
|
|
59
|
+
if ("request" in args[1 + argsPlaceholder])
|
|
60
|
+
instance = args[1 + argsPlaceholder];
|
|
59
61
|
}
|
|
60
|
-
if (args.length === 2 && !("request" in args[1]) || args.length === 3)
|
|
62
|
+
if (args.length === 2 + argsPlaceholder && !("request" in args[1 + argsPlaceholder]) || args.length === 3 + argsPlaceholder)
|
|
61
63
|
options = args[args.length - 1];
|
|
62
64
|
const response = vueDemi.shallowRef();
|
|
63
65
|
const data = vueDemi.shallowRef();
|
|
@@ -78,9 +80,17 @@ function useAxios(url, ...args) {
|
|
|
78
80
|
isLoading.value = loading2;
|
|
79
81
|
isFinished.value = !loading2;
|
|
80
82
|
};
|
|
81
|
-
const execute = (config = {}) => {
|
|
83
|
+
const execute = (executeUrl = url, config = {}) => {
|
|
84
|
+
let _url = "";
|
|
85
|
+
let _config;
|
|
86
|
+
if (typeof executeUrl === "string") {
|
|
87
|
+
_url = executeUrl;
|
|
88
|
+
_config = config;
|
|
89
|
+
} else {
|
|
90
|
+
_config = config;
|
|
91
|
+
}
|
|
82
92
|
loading(true);
|
|
83
|
-
instance(
|
|
93
|
+
instance(_url, __spreadProps$1(__spreadValues$3(__spreadValues$3({}, defaultConfig), _config), { cancelToken: cancelToken.token })).then((r) => {
|
|
84
94
|
response.value = r;
|
|
85
95
|
data.value = r.data;
|
|
86
96
|
}).catch((e) => {
|
|
@@ -89,7 +99,7 @@ function useAxios(url, ...args) {
|
|
|
89
99
|
loading(false);
|
|
90
100
|
});
|
|
91
101
|
};
|
|
92
|
-
if (options.immediate)
|
|
102
|
+
if (options.immediate && url)
|
|
93
103
|
execute();
|
|
94
104
|
const result = {
|
|
95
105
|
response,
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vue_demi from 'vue-demi';
|
|
2
|
-
import { Ref, WritableComputedRef, ComputedRef } from 'vue-demi';
|
|
2
|
+
import { ShallowRef, Ref, WritableComputedRef, ComputedRef } from 'vue-demi';
|
|
3
3
|
import { AxiosResponse, AxiosError, AxiosRequestConfig, AxiosInstance } from 'axios';
|
|
4
4
|
import { camelCase, capitalCase, constantCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase, Options } from 'change-case';
|
|
5
5
|
import { MaybeRef } from '@vueuse/shared';
|
|
@@ -18,7 +18,7 @@ interface UseAxiosReturn<T> {
|
|
|
18
18
|
/**
|
|
19
19
|
* Axios Response
|
|
20
20
|
*/
|
|
21
|
-
response:
|
|
21
|
+
response: ShallowRef<AxiosResponse<T> | undefined>;
|
|
22
22
|
/**
|
|
23
23
|
* Axios response data
|
|
24
24
|
*/
|
|
@@ -38,27 +38,53 @@ interface UseAxiosReturn<T> {
|
|
|
38
38
|
/**
|
|
39
39
|
* Any errors that may have occurred
|
|
40
40
|
*/
|
|
41
|
-
error:
|
|
41
|
+
error: ShallowRef<AxiosError<T> | undefined>;
|
|
42
42
|
/**
|
|
43
43
|
* Aborts the current request
|
|
44
44
|
*/
|
|
45
45
|
abort: (message?: string | undefined) => void;
|
|
46
|
+
/**
|
|
47
|
+
* isFinished alias
|
|
48
|
+
*/
|
|
49
|
+
finished: Ref<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* loading alias
|
|
52
|
+
*/
|
|
53
|
+
loading: Ref<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* abort alias
|
|
56
|
+
*/
|
|
57
|
+
cancel: (message?: string | undefined) => void;
|
|
58
|
+
/**
|
|
59
|
+
* abort aborted
|
|
60
|
+
*/
|
|
61
|
+
canceled: Ref<boolean>;
|
|
62
|
+
}
|
|
63
|
+
interface StrictUseAxiosReturn<T> extends UseAxiosReturn<T> {
|
|
64
|
+
/**
|
|
65
|
+
* Manually call the axios request
|
|
66
|
+
*/
|
|
67
|
+
execute: (url?: string, config?: AxiosRequestConfig) => void;
|
|
68
|
+
}
|
|
69
|
+
interface EasyUseAxiosReturn<T> extends UseAxiosReturn<T> {
|
|
46
70
|
/**
|
|
47
71
|
* Manually call the axios request
|
|
48
72
|
*/
|
|
49
|
-
execute: (config?: AxiosRequestConfig) => void;
|
|
73
|
+
execute: (url: string, config?: AxiosRequestConfig) => void;
|
|
50
74
|
}
|
|
51
75
|
interface UseAxiosOptions {
|
|
52
76
|
/**
|
|
53
77
|
* Will automatically run axios request when `useAxios` is used
|
|
54
78
|
*
|
|
55
|
-
* @default true
|
|
56
79
|
*/
|
|
57
80
|
immediate?: boolean;
|
|
58
81
|
}
|
|
59
|
-
declare function useAxios<T = any>(url: string, config?: AxiosRequestConfig, options?: UseAxiosOptions):
|
|
60
|
-
declare function useAxios<T = any>(url: string, instance?: AxiosInstance, options?: UseAxiosOptions):
|
|
61
|
-
declare function useAxios<T = any>(url: string, config: AxiosRequestConfig, instance: AxiosInstance, options?: UseAxiosOptions):
|
|
82
|
+
declare function useAxios<T = any>(url: string, config?: AxiosRequestConfig, options?: UseAxiosOptions): StrictUseAxiosReturn<T> & PromiseLike<StrictUseAxiosReturn<T>>;
|
|
83
|
+
declare function useAxios<T = any>(url: string, instance?: AxiosInstance, options?: UseAxiosOptions): StrictUseAxiosReturn<T> & PromiseLike<StrictUseAxiosReturn<T>>;
|
|
84
|
+
declare function useAxios<T = any>(url: string, config: AxiosRequestConfig, instance: AxiosInstance, options?: UseAxiosOptions): StrictUseAxiosReturn<T> & PromiseLike<StrictUseAxiosReturn<T>>;
|
|
85
|
+
declare function useAxios<T = any>(config?: AxiosRequestConfig): EasyUseAxiosReturn<T> & PromiseLike<EasyUseAxiosReturn<T>>;
|
|
86
|
+
declare function useAxios<T = any>(instance?: AxiosInstance): EasyUseAxiosReturn<T> & PromiseLike<EasyUseAxiosReturn<T>>;
|
|
87
|
+
declare function useAxios<T = any>(config?: AxiosRequestConfig, instance?: AxiosInstance): EasyUseAxiosReturn<T> & PromiseLike<EasyUseAxiosReturn<T>>;
|
|
62
88
|
|
|
63
89
|
declare const changeCase_camelCase: typeof camelCase;
|
|
64
90
|
declare const changeCase_capitalCase: typeof capitalCase;
|
|
@@ -277,4 +303,4 @@ declare function useNProgress(currentProgress?: MaybeRef<number | null | undefin
|
|
|
277
303
|
*/
|
|
278
304
|
declare function useQRCode(text: MaybeRef<string>, options?: QRCode.QRCodeToDataURLOptions): vue_demi.Ref<string>;
|
|
279
305
|
|
|
280
|
-
export { ChangeCaseType, FuseOptions, JwtOptions, JwtResult, UseAxiosOptions, UseAxiosReturn, UseDrauuOptions, UseDrauuReturn, UseFocusTrapOptions, UseFocusTrapReturn, UseFuseOptions, UseFuseReturn, createCookies, useAxios, useChangeCase, useCookies, useDrauu, useFocusTrap, useFuse, useJwt, useNProgress, useQRCode };
|
|
306
|
+
export { ChangeCaseType, EasyUseAxiosReturn, FuseOptions, JwtOptions, JwtResult, StrictUseAxiosReturn, UseAxiosOptions, UseAxiosReturn, UseDrauuOptions, UseDrauuReturn, UseFocusTrapOptions, UseFocusTrapReturn, UseFuseOptions, UseFuseReturn, createCookies, useAxios, useChangeCase, useCookies, useDrauu, useFocusTrap, useFuse, useJwt, useNProgress, useQRCode };
|
package/index.iife.js
CHANGED
|
@@ -90,21 +90,23 @@
|
|
|
90
90
|
return a;
|
|
91
91
|
};
|
|
92
92
|
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
93
|
-
function useAxios(
|
|
93
|
+
function useAxios(...args) {
|
|
94
|
+
const url = typeof args[0] === "string" ? args[0] : void 0;
|
|
95
|
+
const argsPlaceholder = url ? 1 : 0;
|
|
94
96
|
let defaultConfig = {};
|
|
95
97
|
let instance = axios__default["default"];
|
|
96
|
-
let options = { immediate:
|
|
97
|
-
if (args.length > 0) {
|
|
98
|
-
if ("request" in args[0])
|
|
99
|
-
instance = args[0];
|
|
98
|
+
let options = { immediate: !!argsPlaceholder };
|
|
99
|
+
if (args.length > 0 + argsPlaceholder) {
|
|
100
|
+
if ("request" in args[0 + argsPlaceholder])
|
|
101
|
+
instance = args[0 + argsPlaceholder];
|
|
100
102
|
else
|
|
101
|
-
defaultConfig = args[0];
|
|
103
|
+
defaultConfig = args[0 + argsPlaceholder];
|
|
102
104
|
}
|
|
103
|
-
if (args.length > 1) {
|
|
104
|
-
if ("request" in args[1])
|
|
105
|
-
instance = args[1];
|
|
105
|
+
if (args.length > 1 + argsPlaceholder) {
|
|
106
|
+
if ("request" in args[1 + argsPlaceholder])
|
|
107
|
+
instance = args[1 + argsPlaceholder];
|
|
106
108
|
}
|
|
107
|
-
if (args.length === 2 && !("request" in args[1]) || args.length === 3)
|
|
109
|
+
if (args.length === 2 + argsPlaceholder && !("request" in args[1 + argsPlaceholder]) || args.length === 3 + argsPlaceholder)
|
|
108
110
|
options = args[args.length - 1];
|
|
109
111
|
const response = vueDemi.shallowRef();
|
|
110
112
|
const data = vueDemi.shallowRef();
|
|
@@ -125,9 +127,17 @@
|
|
|
125
127
|
isLoading.value = loading2;
|
|
126
128
|
isFinished.value = !loading2;
|
|
127
129
|
};
|
|
128
|
-
const execute = (config = {}) => {
|
|
130
|
+
const execute = (executeUrl = url, config = {}) => {
|
|
131
|
+
let _url = "";
|
|
132
|
+
let _config;
|
|
133
|
+
if (typeof executeUrl === "string") {
|
|
134
|
+
_url = executeUrl;
|
|
135
|
+
_config = config;
|
|
136
|
+
} else {
|
|
137
|
+
_config = config;
|
|
138
|
+
}
|
|
129
139
|
loading(true);
|
|
130
|
-
instance(
|
|
140
|
+
instance(_url, __spreadProps$1(__spreadValues$3(__spreadValues$3({}, defaultConfig), _config), { cancelToken: cancelToken.token })).then((r) => {
|
|
131
141
|
response.value = r;
|
|
132
142
|
data.value = r.data;
|
|
133
143
|
}).catch((e) => {
|
|
@@ -136,7 +146,7 @@
|
|
|
136
146
|
loading(false);
|
|
137
147
|
});
|
|
138
148
|
};
|
|
139
|
-
if (options.immediate)
|
|
149
|
+
if (options.immediate && url)
|
|
140
150
|
execute();
|
|
141
151
|
const result = {
|
|
142
152
|
response,
|
package/index.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(v){if(!v.VueDemi){var n={},c=v.Vue;if(c)if(c.version.slice(0,2)==="2."){var
|
|
1
|
+
(function(v){if(!v.VueDemi){var n={},c=v.Vue;if(c)if(c.version.slice(0,2)==="2."){var j=v.VueCompositionAPI;if(j){for(var d in j)n[d]=j[d];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=c,n.Vue2=c,n.version=c.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.")}else if(c.version.slice(0,2)==="3."){for(var d in c)n[d]=c[d];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=c,n.Vue2=void 0,n.version=c.version,n.set=function(C,y,h){return Array.isArray(C)?(C.length=Math.max(C.length,y),C.splice(y,1,h),h):(C[y]=h,h)},n.del=function(C,y){if(Array.isArray(C)){C.splice(y,1);return}delete C[y]}}else console.error("[vue-demi] Vue version "+c.version+" is unsupported.");else console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.");v.VueDemi=n}})(window),function(v,n,c,j,d,C,y,h,Y,Z,x,D,ee){"use strict";function V(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var k=V(j),N=V(C),te=V(Z),re=V(x),P=V(D),ne=V(ee),ae=Object.defineProperty,oe=Object.defineProperties,le=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,se=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable,U=(t,r,e)=>r in t?ae(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,H=(t,r)=>{for(var e in r||(r={}))se.call(r,e)&&U(t,e,r[e]);if(T)for(var e of T(r))ue.call(r,e)&&U(t,e,r[e]);return t},G=(t,r)=>oe(t,le(r));function fe(...t){const r=typeof t[0]=="string"?t[0]:void 0,e=r?1:0;let a={},s=k.default,f={immediate:!!e};t.length>0+e&&("request"in t[0+e]?s=t[0+e]:a=t[0+e]),t.length>1+e&&"request"in t[1+e]&&(s=t[1+e]),(t.length===2+e&&!("request"in t[1+e])||t.length===3+e)&&(f=t[t.length-1]);const p=n.shallowRef(),u=n.shallowRef(),o=n.ref(!1),i=n.ref(!1),_=n.ref(!1),m=n.shallowRef(),w=k.default.CancelToken.source(),E=O=>{o.value||!i.value||(w.cancel(O),_.value=!0,i.value=!1,o.value=!1)},R=O=>{i.value=O,o.value=!O},F=(O=r,g={})=>{let b="",S;typeof O=="string"&&(b=O),S=g,R(!0),s(b,G(H(H({},a),S),{cancelToken:w.token})).then(l=>{p.value=l,u.value=l.data}).catch(l=>{m.value=l}).finally(()=>{R(!1)})};f.immediate&&r&&F();const $={response:p,data:u,error:m,finished:o,loading:i,isFinished:o,isLoading:i,cancel:E,canceled:_,aborted:_,abort:E,execute:F};function I(){return new Promise((O,g)=>{c.until(o).toBe(!0).then(()=>O($)).catch(b=>g(b))})}return G(H({},$),{then(O,g){return I().then(O,g)}})}var ce=Object.freeze({__proto__:null,camelCase:d.camelCase,capitalCase:d.capitalCase,constantCase:d.constantCase,dotCase:d.dotCase,headerCase:d.headerCase,noCase:d.noCase,paramCase:d.paramCase,pascalCase:d.pascalCase,pathCase:d.pathCase,sentenceCase:d.sentenceCase,snakeCase:d.snakeCase});function ie(t,r,e){const a=n.ref(t);return n.computed({get(){return ce[r](a.value,e)},set(s){a.value=s}})}var de=Object.defineProperty,Q=Object.getOwnPropertySymbols,ve=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable,J=(t,r,e)=>r in t?de(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,q=(t,r)=>{for(var e in r||(r={}))ve.call(r,e)&&J(t,e,r[e]);if(Q)for(var e of Q(r))pe.call(r,e)&&J(t,e,r[e]);return t};function _e(t){const r=new N.default(t?t.headers.cookie:null);return(e,{doNotParse:a=!1,autoUpdateDependencies:s=!1}={})=>z(e,{doNotParse:a,autoUpdateDependencies:s},r)}function z(t,{doNotParse:r=!1,autoUpdateDependencies:e=!1}={},a=new N.default){const s=e?[...t||[]]:t;let f=a.getAll({doNotParse:!0});const p=n.ref(0),u=()=>{const o=a.getAll({doNotParse:!0});he(s||null,o,f)&&p.value++,f=o};return a.addChangeListener(u),c.tryOnScopeDispose(()=>{a.removeChangeListener(u)}),{get:(...o)=>(e&&s&&!s.includes(o[0])&&s.push(o[0]),p.value,a.get(o[0],q({doNotParse:r},o[1]))),getAll:(...o)=>(p.value,a.getAll(q({doNotParse:r},o[0]))),set:(...o)=>a.set(...o),remove:(...o)=>a.remove(...o),addChangeListener:(...o)=>a.addChangeListener(...o),removeChangeListener:(...o)=>a.removeChangeListener(...o)}}function he(t,r,e){if(!t)return!0;for(const a of t)if(r[a]!==e[a])return!0;return!1}var Oe=Object.defineProperty,M=Object.getOwnPropertySymbols,Ce=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable,W=(t,r,e)=>r in t?Oe(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,we=(t,r)=>{for(var e in r||(r={}))Ce.call(r,e)&&W(t,e,r[e]);if(M)for(var e of M(r))Pe.call(r,e)&&W(t,e,r[e]);return t};function ye(t,r){const e=n.ref();let a=[];const s=h.createEventHook(),f=h.createEventHook(),p=h.createEventHook(),u=h.createEventHook(),o=h.createEventHook(),i=n.ref(!1),_=n.ref(!1),m=n.ref(!1),w=n.ref(!1),E=n.ref({color:"black",size:3,arrowEnd:!1,cornerRadius:0,dasharray:void 0,fill:"transparent",mode:"draw"});n.watch(E,()=>{const l=e.value;l&&(l.brush=E.value)},{deep:!0});const R=()=>{var l;return(l=e.value)==null?void 0:l.undo()},F=()=>{var l;return(l=e.value)==null?void 0:l.redo()},$=()=>{var l;return(l=e.value)==null?void 0:l.clear()},I=()=>{var l;return(l=e.value)==null?void 0:l.cancel()},O=l=>{var L;return(L=e.value)==null?void 0:L.load(l)},g=()=>{var l;return(l=e.value)==null?void 0:l.dump()},b=()=>{var l;a.forEach(L=>L()),(l=e.value)==null||l.unmount()},S=()=>{e.value&&(i.value=e.value.canUndo(),_.value=e.value.canRedo(),m.value=e.value.altPressed,w.value=e.value.shiftPressed)};return n.watch(()=>h.unrefElement(t),l=>{!l||typeof SVGSVGElement=="undefined"||!(l instanceof SVGSVGElement)||(e.value&&b(),e.value=y.createDrauu(we({el:l},r)),S(),a=[e.value.on("canceled",()=>f.trigger()),e.value.on("committed",()=>p.trigger()),e.value.on("start",()=>u.trigger()),e.value.on("end",()=>o.trigger()),e.value.on("changed",()=>{S(),s.trigger()})])},{flush:"post"}),c.tryOnScopeDispose(()=>b()),{drauuInstance:e,load:O,dump:g,clear:$,cancel:I,undo:R,redo:F,canUndo:i,canRedo:_,brush:E,onChanged:s.on,onCommitted:p.on,onStart:u.on,onEnd:o.on,onCanceled:f.on}}var me=Object.defineProperty,ge=Object.defineProperties,be=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertySymbols,B=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable,X=(t,r,e)=>r in t?me(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,Ve=(t,r)=>{for(var e in r||(r={}))B.call(r,e)&&X(t,e,r[e]);if(A)for(var e of A(r))K.call(r,e)&&X(t,e,r[e]);return t},Ee=(t,r)=>ge(t,be(r)),Se=(t,r)=>{var e={};for(var a in t)B.call(t,a)&&r.indexOf(a)<0&&(e[a]=t[a]);if(t!=null&&A)for(var a of A(t))r.indexOf(a)<0&&K.call(t,a)&&(e[a]=t[a]);return e};function je(t,r={}){let e;const a=r,{immediate:s}=a,f=Se(a,["immediate"]),p=n.ref(!1),u=n.ref(!1),o=w=>e&&e.activate(w),i=w=>e&&e.deactivate(w),_=()=>{e&&(e.pause(),u.value=!0)},m=()=>{e&&(e.unpause(),u.value=!1)};return n.watch(()=>h.unrefElement(t),w=>{!w||(e=Y.createFocusTrap(w,Ee(Ve({},f),{onActivate(){p.value=!0,r.onActivate&&r.onActivate()},onDeactivate(){p.value=!1,r.onDeactivate&&r.onDeactivate()}})),s&&o())},{flush:"post"}),h.tryOnScopeDispose(()=>i()),{hasFocus:p,isPaused:u,activate:o,deactivate:i,pause:_,unpause:m}}function Ae(t,r,e){var a;const s=(u,o)=>{var i;const _=o;return new te.default((i=n.unref(u))!=null?i:[],_)},f=n.ref(s(r,(a=n.unref(e))==null?void 0:a.fuseOptions));return n.watch(()=>{var u;return(u=n.unref(e))==null?void 0:u.fuseOptions},u=>{f.value=s(r,u)},{deep:!0}),n.watch(()=>n.unref(r),u=>{f.value.setCollection(u)},{deep:!0}),{results:n.computed(()=>{var u,o;if(((u=n.unref(e))==null?void 0:u.matchAllWhenSearchEmpty)&&!n.unref(t))return n.unref(r).map((_,m)=>({item:_,refIndex:m}));const i=(o=n.unref(e))==null?void 0:o.resultLimit;return f.value.search(n.unref(t),i?{limit:i}:void 0)})}}function Re(t,r={}){const e=n.ref(t),{onError:a,fallbackValue:s=null}=r,f=(o,i)=>{try{return re.default(o,i)}catch(_){return a==null||a(_),s}},p=n.computed(()=>f(e.value,{header:!0})),u=n.computed(()=>f(e.value));return{header:p,payload:u}}function Fe(t=null,r){const e=n.isRef(t)?t:n.ref(t),a=n.computed({set:f=>f?P.default.start():P.default.done(),get:()=>c.isNumber(e.value)&&e.value<1});r&&P.default.configure(r);const s=P.default.set;return P.default.set=f=>(e.value=f,s.call(P.default,f)),n.watchEffect(()=>{c.isNumber(e.value)&&s.call(P.default,e.value)}),c.tryOnScopeDispose(P.default.remove),{isLoading:a,progress:e,start:P.default.start,done:P.default.done,remove:()=>{e.value=null,P.default.remove()}}}function $e(t,r){const e=n.ref(t),a=n.ref("");return n.watch(e,async s=>{e.value&&c.isClient&&(a.value=await ne.default.toDataURL(s,r))},{immediate:!0}),a}v.createCookies=_e,v.useAxios=fe,v.useChangeCase=ie,v.useCookies=z,v.useDrauu=ye,v.useFocusTrap=je,v.useFuse=Ae,v.useJwt=Re,v.useNProgress=Fe,v.useQRCode=$e,Object.defineProperty(v,"__esModule",{value:!0})}(this.VueUse=this.VueUse||{},VueDemi,VueUse,axios,changeCase$1,UniversalCookie,Drauu,VueUse,focusTrap,Fuse,jwt_decode,nprogress,QRCode);
|
package/index.mjs
CHANGED
|
@@ -30,21 +30,23 @@ var __spreadValues$3 = (a, b) => {
|
|
|
30
30
|
return a;
|
|
31
31
|
};
|
|
32
32
|
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
33
|
-
function useAxios(
|
|
33
|
+
function useAxios(...args) {
|
|
34
|
+
const url = typeof args[0] === "string" ? args[0] : void 0;
|
|
35
|
+
const argsPlaceholder = url ? 1 : 0;
|
|
34
36
|
let defaultConfig = {};
|
|
35
37
|
let instance = axios;
|
|
36
|
-
let options = { immediate:
|
|
37
|
-
if (args.length > 0) {
|
|
38
|
-
if ("request" in args[0])
|
|
39
|
-
instance = args[0];
|
|
38
|
+
let options = { immediate: !!argsPlaceholder };
|
|
39
|
+
if (args.length > 0 + argsPlaceholder) {
|
|
40
|
+
if ("request" in args[0 + argsPlaceholder])
|
|
41
|
+
instance = args[0 + argsPlaceholder];
|
|
40
42
|
else
|
|
41
|
-
defaultConfig = args[0];
|
|
43
|
+
defaultConfig = args[0 + argsPlaceholder];
|
|
42
44
|
}
|
|
43
|
-
if (args.length > 1) {
|
|
44
|
-
if ("request" in args[1])
|
|
45
|
-
instance = args[1];
|
|
45
|
+
if (args.length > 1 + argsPlaceholder) {
|
|
46
|
+
if ("request" in args[1 + argsPlaceholder])
|
|
47
|
+
instance = args[1 + argsPlaceholder];
|
|
46
48
|
}
|
|
47
|
-
if (args.length === 2 && !("request" in args[1]) || args.length === 3)
|
|
49
|
+
if (args.length === 2 + argsPlaceholder && !("request" in args[1 + argsPlaceholder]) || args.length === 3 + argsPlaceholder)
|
|
48
50
|
options = args[args.length - 1];
|
|
49
51
|
const response = shallowRef();
|
|
50
52
|
const data = shallowRef();
|
|
@@ -65,9 +67,17 @@ function useAxios(url, ...args) {
|
|
|
65
67
|
isLoading.value = loading2;
|
|
66
68
|
isFinished.value = !loading2;
|
|
67
69
|
};
|
|
68
|
-
const execute = (config = {}) => {
|
|
70
|
+
const execute = (executeUrl = url, config = {}) => {
|
|
71
|
+
let _url = "";
|
|
72
|
+
let _config;
|
|
73
|
+
if (typeof executeUrl === "string") {
|
|
74
|
+
_url = executeUrl;
|
|
75
|
+
_config = config;
|
|
76
|
+
} else {
|
|
77
|
+
_config = config;
|
|
78
|
+
}
|
|
69
79
|
loading(true);
|
|
70
|
-
instance(
|
|
80
|
+
instance(_url, __spreadProps$1(__spreadValues$3(__spreadValues$3({}, defaultConfig), _config), { cancelToken: cancelToken.token })).then((r) => {
|
|
71
81
|
response.value = r;
|
|
72
82
|
data.value = r.data;
|
|
73
83
|
}).catch((e) => {
|
|
@@ -76,7 +86,7 @@ function useAxios(url, ...args) {
|
|
|
76
86
|
loading(false);
|
|
77
87
|
});
|
|
78
88
|
};
|
|
79
|
-
if (options.immediate)
|
|
89
|
+
if (options.immediate && url)
|
|
80
90
|
execute();
|
|
81
91
|
const result = {
|
|
82
92
|
response,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vueuse/integrations",
|
|
3
|
-
"version": "8.0.0
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Integration wrappers for utility libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vue",
|
|
@@ -12,14 +12,18 @@
|
|
|
12
12
|
"url": "https://github.com/vueuse/vueuse/issues"
|
|
13
13
|
},
|
|
14
14
|
"license": "MIT",
|
|
15
|
+
"author": "Anthony Fu <https://github.com/antfu>",
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|
|
17
18
|
"url": "git+https://github.com/vueuse/vueuse.git",
|
|
18
19
|
"directory": "packages/integrations"
|
|
19
20
|
},
|
|
20
21
|
"funding": "https://github.com/sponsors/antfu",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
22
|
+
"main": "./index.cjs",
|
|
23
|
+
"module": "./index.mjs",
|
|
24
|
+
"types": "./index.d.ts",
|
|
25
|
+
"unpkg": "./index.iife.min.js",
|
|
26
|
+
"jsdelivr": "./index.iife.min.js",
|
|
23
27
|
"exports": {
|
|
24
28
|
".": {
|
|
25
29
|
"import": "./index.mjs",
|
|
@@ -78,11 +82,7 @@
|
|
|
78
82
|
"types": "./useChangeCase.d.ts"
|
|
79
83
|
}
|
|
80
84
|
},
|
|
81
|
-
"
|
|
82
|
-
"jsdelivr": "./index.iife.min.js",
|
|
83
|
-
"module": "./index.mjs",
|
|
84
|
-
"unpkg": "./index.iife.min.js",
|
|
85
|
-
"types": "./index.d.ts",
|
|
85
|
+
"sideEffects": false,
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"axios": "*",
|
|
88
88
|
"change-case": "*",
|
|
@@ -121,14 +121,14 @@
|
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
"dependencies": {
|
|
124
|
-
"@vueuse/core": "8.0.0
|
|
125
|
-
"@vueuse/shared": "8.0.0
|
|
124
|
+
"@vueuse/core": "8.0.0",
|
|
125
|
+
"@vueuse/shared": "8.0.0",
|
|
126
126
|
"vue-demi": "*"
|
|
127
127
|
},
|
|
128
128
|
"devDependencies": {
|
|
129
129
|
"@types/nprogress": "^0.2.0",
|
|
130
130
|
"@types/qrcode": "^1.4.2",
|
|
131
|
-
"axios": "^0.26.
|
|
131
|
+
"axios": "^0.26.1",
|
|
132
132
|
"change-case": "^4.1.2",
|
|
133
133
|
"drauu": "^0.3.0",
|
|
134
134
|
"focus-trap": "^6.7.3",
|
package/useAxios.cjs
CHANGED
|
@@ -29,21 +29,23 @@ var __spreadValues = (a, b) => {
|
|
|
29
29
|
return a;
|
|
30
30
|
};
|
|
31
31
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
32
|
-
function useAxios(
|
|
32
|
+
function useAxios(...args) {
|
|
33
|
+
const url = typeof args[0] === "string" ? args[0] : void 0;
|
|
34
|
+
const argsPlaceholder = url ? 1 : 0;
|
|
33
35
|
let defaultConfig = {};
|
|
34
36
|
let instance = axios__default["default"];
|
|
35
|
-
let options = { immediate:
|
|
36
|
-
if (args.length > 0) {
|
|
37
|
-
if ("request" in args[0])
|
|
38
|
-
instance = args[0];
|
|
37
|
+
let options = { immediate: !!argsPlaceholder };
|
|
38
|
+
if (args.length > 0 + argsPlaceholder) {
|
|
39
|
+
if ("request" in args[0 + argsPlaceholder])
|
|
40
|
+
instance = args[0 + argsPlaceholder];
|
|
39
41
|
else
|
|
40
|
-
defaultConfig = args[0];
|
|
42
|
+
defaultConfig = args[0 + argsPlaceholder];
|
|
41
43
|
}
|
|
42
|
-
if (args.length > 1) {
|
|
43
|
-
if ("request" in args[1])
|
|
44
|
-
instance = args[1];
|
|
44
|
+
if (args.length > 1 + argsPlaceholder) {
|
|
45
|
+
if ("request" in args[1 + argsPlaceholder])
|
|
46
|
+
instance = args[1 + argsPlaceholder];
|
|
45
47
|
}
|
|
46
|
-
if (args.length === 2 && !("request" in args[1]) || args.length === 3)
|
|
48
|
+
if (args.length === 2 + argsPlaceholder && !("request" in args[1 + argsPlaceholder]) || args.length === 3 + argsPlaceholder)
|
|
47
49
|
options = args[args.length - 1];
|
|
48
50
|
const response = vueDemi.shallowRef();
|
|
49
51
|
const data = vueDemi.shallowRef();
|
|
@@ -64,9 +66,17 @@ function useAxios(url, ...args) {
|
|
|
64
66
|
isLoading.value = loading2;
|
|
65
67
|
isFinished.value = !loading2;
|
|
66
68
|
};
|
|
67
|
-
const execute = (config = {}) => {
|
|
69
|
+
const execute = (executeUrl = url, config = {}) => {
|
|
70
|
+
let _url = "";
|
|
71
|
+
let _config;
|
|
72
|
+
if (typeof executeUrl === "string") {
|
|
73
|
+
_url = executeUrl;
|
|
74
|
+
_config = config;
|
|
75
|
+
} else {
|
|
76
|
+
_config = config;
|
|
77
|
+
}
|
|
68
78
|
loading(true);
|
|
69
|
-
instance(
|
|
79
|
+
instance(_url, __spreadProps(__spreadValues(__spreadValues({}, defaultConfig), _config), { cancelToken: cancelToken.token })).then((r) => {
|
|
70
80
|
response.value = r;
|
|
71
81
|
data.value = r.data;
|
|
72
82
|
}).catch((e) => {
|
|
@@ -75,7 +85,7 @@ function useAxios(url, ...args) {
|
|
|
75
85
|
loading(false);
|
|
76
86
|
});
|
|
77
87
|
};
|
|
78
|
-
if (options.immediate)
|
|
88
|
+
if (options.immediate && url)
|
|
79
89
|
execute();
|
|
80
90
|
const result = {
|
|
81
91
|
response,
|
package/useAxios.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Ref } from 'vue-demi';
|
|
1
|
+
import { ShallowRef, Ref } from 'vue-demi';
|
|
2
2
|
import { AxiosResponse, AxiosError, AxiosRequestConfig, AxiosInstance } from 'axios';
|
|
3
3
|
|
|
4
4
|
interface UseAxiosReturn<T> {
|
|
5
5
|
/**
|
|
6
6
|
* Axios Response
|
|
7
7
|
*/
|
|
8
|
-
response:
|
|
8
|
+
response: ShallowRef<AxiosResponse<T> | undefined>;
|
|
9
9
|
/**
|
|
10
10
|
* Axios response data
|
|
11
11
|
*/
|
|
@@ -25,26 +25,52 @@ interface UseAxiosReturn<T> {
|
|
|
25
25
|
/**
|
|
26
26
|
* Any errors that may have occurred
|
|
27
27
|
*/
|
|
28
|
-
error:
|
|
28
|
+
error: ShallowRef<AxiosError<T> | undefined>;
|
|
29
29
|
/**
|
|
30
30
|
* Aborts the current request
|
|
31
31
|
*/
|
|
32
32
|
abort: (message?: string | undefined) => void;
|
|
33
|
+
/**
|
|
34
|
+
* isFinished alias
|
|
35
|
+
*/
|
|
36
|
+
finished: Ref<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* loading alias
|
|
39
|
+
*/
|
|
40
|
+
loading: Ref<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* abort alias
|
|
43
|
+
*/
|
|
44
|
+
cancel: (message?: string | undefined) => void;
|
|
45
|
+
/**
|
|
46
|
+
* abort aborted
|
|
47
|
+
*/
|
|
48
|
+
canceled: Ref<boolean>;
|
|
49
|
+
}
|
|
50
|
+
interface StrictUseAxiosReturn<T> extends UseAxiosReturn<T> {
|
|
51
|
+
/**
|
|
52
|
+
* Manually call the axios request
|
|
53
|
+
*/
|
|
54
|
+
execute: (url?: string, config?: AxiosRequestConfig) => void;
|
|
55
|
+
}
|
|
56
|
+
interface EasyUseAxiosReturn<T> extends UseAxiosReturn<T> {
|
|
33
57
|
/**
|
|
34
58
|
* Manually call the axios request
|
|
35
59
|
*/
|
|
36
|
-
execute: (config?: AxiosRequestConfig) => void;
|
|
60
|
+
execute: (url: string, config?: AxiosRequestConfig) => void;
|
|
37
61
|
}
|
|
38
62
|
interface UseAxiosOptions {
|
|
39
63
|
/**
|
|
40
64
|
* Will automatically run axios request when `useAxios` is used
|
|
41
65
|
*
|
|
42
|
-
* @default true
|
|
43
66
|
*/
|
|
44
67
|
immediate?: boolean;
|
|
45
68
|
}
|
|
46
|
-
declare function useAxios<T = any>(url: string, config?: AxiosRequestConfig, options?: UseAxiosOptions):
|
|
47
|
-
declare function useAxios<T = any>(url: string, instance?: AxiosInstance, options?: UseAxiosOptions):
|
|
48
|
-
declare function useAxios<T = any>(url: string, config: AxiosRequestConfig, instance: AxiosInstance, options?: UseAxiosOptions):
|
|
69
|
+
declare function useAxios<T = any>(url: string, config?: AxiosRequestConfig, options?: UseAxiosOptions): StrictUseAxiosReturn<T> & PromiseLike<StrictUseAxiosReturn<T>>;
|
|
70
|
+
declare function useAxios<T = any>(url: string, instance?: AxiosInstance, options?: UseAxiosOptions): StrictUseAxiosReturn<T> & PromiseLike<StrictUseAxiosReturn<T>>;
|
|
71
|
+
declare function useAxios<T = any>(url: string, config: AxiosRequestConfig, instance: AxiosInstance, options?: UseAxiosOptions): StrictUseAxiosReturn<T> & PromiseLike<StrictUseAxiosReturn<T>>;
|
|
72
|
+
declare function useAxios<T = any>(config?: AxiosRequestConfig): EasyUseAxiosReturn<T> & PromiseLike<EasyUseAxiosReturn<T>>;
|
|
73
|
+
declare function useAxios<T = any>(instance?: AxiosInstance): EasyUseAxiosReturn<T> & PromiseLike<EasyUseAxiosReturn<T>>;
|
|
74
|
+
declare function useAxios<T = any>(config?: AxiosRequestConfig, instance?: AxiosInstance): EasyUseAxiosReturn<T> & PromiseLike<EasyUseAxiosReturn<T>>;
|
|
49
75
|
|
|
50
|
-
export { UseAxiosOptions, UseAxiosReturn, useAxios };
|
|
76
|
+
export { EasyUseAxiosReturn, StrictUseAxiosReturn, UseAxiosOptions, UseAxiosReturn, useAxios };
|
package/useAxios.iife.js
CHANGED
|
@@ -85,21 +85,23 @@
|
|
|
85
85
|
return a;
|
|
86
86
|
};
|
|
87
87
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
88
|
-
function useAxios(
|
|
88
|
+
function useAxios(...args) {
|
|
89
|
+
const url = typeof args[0] === "string" ? args[0] : void 0;
|
|
90
|
+
const argsPlaceholder = url ? 1 : 0;
|
|
89
91
|
let defaultConfig = {};
|
|
90
92
|
let instance = axios__default["default"];
|
|
91
|
-
let options = { immediate:
|
|
92
|
-
if (args.length > 0) {
|
|
93
|
-
if ("request" in args[0])
|
|
94
|
-
instance = args[0];
|
|
93
|
+
let options = { immediate: !!argsPlaceholder };
|
|
94
|
+
if (args.length > 0 + argsPlaceholder) {
|
|
95
|
+
if ("request" in args[0 + argsPlaceholder])
|
|
96
|
+
instance = args[0 + argsPlaceholder];
|
|
95
97
|
else
|
|
96
|
-
defaultConfig = args[0];
|
|
98
|
+
defaultConfig = args[0 + argsPlaceholder];
|
|
97
99
|
}
|
|
98
|
-
if (args.length > 1) {
|
|
99
|
-
if ("request" in args[1])
|
|
100
|
-
instance = args[1];
|
|
100
|
+
if (args.length > 1 + argsPlaceholder) {
|
|
101
|
+
if ("request" in args[1 + argsPlaceholder])
|
|
102
|
+
instance = args[1 + argsPlaceholder];
|
|
101
103
|
}
|
|
102
|
-
if (args.length === 2 && !("request" in args[1]) || args.length === 3)
|
|
104
|
+
if (args.length === 2 + argsPlaceholder && !("request" in args[1 + argsPlaceholder]) || args.length === 3 + argsPlaceholder)
|
|
103
105
|
options = args[args.length - 1];
|
|
104
106
|
const response = vueDemi.shallowRef();
|
|
105
107
|
const data = vueDemi.shallowRef();
|
|
@@ -120,9 +122,17 @@
|
|
|
120
122
|
isLoading.value = loading2;
|
|
121
123
|
isFinished.value = !loading2;
|
|
122
124
|
};
|
|
123
|
-
const execute = (config = {}) => {
|
|
125
|
+
const execute = (executeUrl = url, config = {}) => {
|
|
126
|
+
let _url = "";
|
|
127
|
+
let _config;
|
|
128
|
+
if (typeof executeUrl === "string") {
|
|
129
|
+
_url = executeUrl;
|
|
130
|
+
_config = config;
|
|
131
|
+
} else {
|
|
132
|
+
_config = config;
|
|
133
|
+
}
|
|
124
134
|
loading(true);
|
|
125
|
-
instance(
|
|
135
|
+
instance(_url, __spreadProps(__spreadValues(__spreadValues({}, defaultConfig), _config), { cancelToken: cancelToken.token })).then((r) => {
|
|
126
136
|
response.value = r;
|
|
127
137
|
data.value = r.data;
|
|
128
138
|
}).catch((e) => {
|
|
@@ -131,7 +141,7 @@
|
|
|
131
141
|
loading(false);
|
|
132
142
|
});
|
|
133
143
|
};
|
|
134
|
-
if (options.immediate)
|
|
144
|
+
if (options.immediate && url)
|
|
135
145
|
execute();
|
|
136
146
|
const result = {
|
|
137
147
|
response,
|
package/useAxios.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(l){if(!l.VueDemi){var n={},o=l.Vue;if(o)if(o.version.slice(0,2)==="2."){var p=l.VueCompositionAPI;if(p){for(var a in p)n[a]=p[a];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=o,n.Vue2=o,n.version=o.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.")}else if(o.version.slice(0,2)==="3."){for(var a in o)n[a]=o[a];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=o,n.Vue2=void 0,n.version=o.version,n.set=function(i,u,f){return Array.isArray(i)?(i.length=Math.max(i.length,u),i.splice(u,1,f),f):(i[u]=f,f)},n.del=function(i,u){if(Array.isArray(i)){i.splice(u,1);return}delete i[u]}}else console.error("[vue-demi] Vue version "+o.version+" is unsupported.");else console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.");l.VueDemi=n}})(window),function(l,n,o,p){"use strict";function a(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var i=a(p),u=Object.defineProperty,f=Object.defineProperties,F=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,I=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable,b=(e,r,t)=>r in e?u(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,V=(e,r)=>{for(var t in r||(r={}))I.call(r,t)&&b(e,t,r[t]);if(O)for(var t of O(r))L.call(r,t)&&b(e,t,r[t]);return e},w=(e,r)=>f(e,F(r));function M(...e){const r=typeof e[0]=="string"?e[0]:void 0,t=r?1:0;let j={},m=i.default,A={immediate:!!t};e.length>0+t&&("request"in e[0+t]?m=e[0+t]:j=e[0+t]),e.length>1+t&&"request"in e[1+t]&&(m=e[1+t]),(e.length===2+t&&!("request"in e[1+t])||e.length===3+t)&&(A=e[e.length-1]);const x=n.shallowRef(),q=n.shallowRef(),c=n.ref(!1),v=n.ref(!1),P=n.ref(!1),R=n.shallowRef(),T=i.default.CancelToken.source(),U=s=>{c.value||!v.value||(T.cancel(s),P.value=!0,v.value=!1,c.value=!1)},C=s=>{v.value=s,c.value=!s},D=(s=r,d={})=>{let h="",y;typeof s=="string"&&(h=s),y=d,C(!0),m(h,w(V(V({},j),y),{cancelToken:T.token})).then(_=>{x.value=_,q.value=_.data}).catch(_=>{R.value=_}).finally(()=>{C(!1)})};A.immediate&&r&&D();const E={response:x,data:q,error:R,finished:c,loading:v,isFinished:c,isLoading:v,cancel:U,canceled:P,aborted:P,abort:U,execute:D};function S(){return new Promise((s,d)=>{o.until(c).toBe(!0).then(()=>s(E)).catch(h=>d(h))})}return w(V({},E),{then(s,d){return S().then(s,d)}})}l.useAxios=M,Object.defineProperty(l,"__esModule",{value:!0})}(this.VueUse=this.VueUse||{},VueDemi,VueUse,axios);
|
package/useAxios.mjs
CHANGED
|
@@ -21,21 +21,23 @@ var __spreadValues = (a, b) => {
|
|
|
21
21
|
return a;
|
|
22
22
|
};
|
|
23
23
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
function useAxios(
|
|
24
|
+
function useAxios(...args) {
|
|
25
|
+
const url = typeof args[0] === "string" ? args[0] : void 0;
|
|
26
|
+
const argsPlaceholder = url ? 1 : 0;
|
|
25
27
|
let defaultConfig = {};
|
|
26
28
|
let instance = axios;
|
|
27
|
-
let options = { immediate:
|
|
28
|
-
if (args.length > 0) {
|
|
29
|
-
if ("request" in args[0])
|
|
30
|
-
instance = args[0];
|
|
29
|
+
let options = { immediate: !!argsPlaceholder };
|
|
30
|
+
if (args.length > 0 + argsPlaceholder) {
|
|
31
|
+
if ("request" in args[0 + argsPlaceholder])
|
|
32
|
+
instance = args[0 + argsPlaceholder];
|
|
31
33
|
else
|
|
32
|
-
defaultConfig = args[0];
|
|
34
|
+
defaultConfig = args[0 + argsPlaceholder];
|
|
33
35
|
}
|
|
34
|
-
if (args.length > 1) {
|
|
35
|
-
if ("request" in args[1])
|
|
36
|
-
instance = args[1];
|
|
36
|
+
if (args.length > 1 + argsPlaceholder) {
|
|
37
|
+
if ("request" in args[1 + argsPlaceholder])
|
|
38
|
+
instance = args[1 + argsPlaceholder];
|
|
37
39
|
}
|
|
38
|
-
if (args.length === 2 && !("request" in args[1]) || args.length === 3)
|
|
40
|
+
if (args.length === 2 + argsPlaceholder && !("request" in args[1 + argsPlaceholder]) || args.length === 3 + argsPlaceholder)
|
|
39
41
|
options = args[args.length - 1];
|
|
40
42
|
const response = shallowRef();
|
|
41
43
|
const data = shallowRef();
|
|
@@ -56,9 +58,17 @@ function useAxios(url, ...args) {
|
|
|
56
58
|
isLoading.value = loading2;
|
|
57
59
|
isFinished.value = !loading2;
|
|
58
60
|
};
|
|
59
|
-
const execute = (config = {}) => {
|
|
61
|
+
const execute = (executeUrl = url, config = {}) => {
|
|
62
|
+
let _url = "";
|
|
63
|
+
let _config;
|
|
64
|
+
if (typeof executeUrl === "string") {
|
|
65
|
+
_url = executeUrl;
|
|
66
|
+
_config = config;
|
|
67
|
+
} else {
|
|
68
|
+
_config = config;
|
|
69
|
+
}
|
|
60
70
|
loading(true);
|
|
61
|
-
instance(
|
|
71
|
+
instance(_url, __spreadProps(__spreadValues(__spreadValues({}, defaultConfig), _config), { cancelToken: cancelToken.token })).then((r) => {
|
|
62
72
|
response.value = r;
|
|
63
73
|
data.value = r.data;
|
|
64
74
|
}).catch((e) => {
|
|
@@ -67,7 +77,7 @@ function useAxios(url, ...args) {
|
|
|
67
77
|
loading(false);
|
|
68
78
|
});
|
|
69
79
|
};
|
|
70
|
-
if (options.immediate)
|
|
80
|
+
if (options.immediate && url)
|
|
71
81
|
execute();
|
|
72
82
|
const result = {
|
|
73
83
|
response,
|