@vueuse/integrations 9.2.0 → 9.3.1
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 +20 -32
- package/index.d.ts +19 -13
- package/index.iife.js +114 -85
- package/index.iife.min.js +1 -1
- package/index.mjs +2 -2
- package/package.json +6 -6
- package/useAsyncValidator/component.cjs +1 -7
- package/useAsyncValidator.cjs +1 -7
- package/useAsyncValidator.iife.js +95 -60
- package/useAsyncValidator.iife.min.js +1 -1
- package/useAxios.cjs +4 -10
- package/useAxios.d.ts +19 -13
- package/useAxios.iife.js +98 -63
- package/useAxios.iife.min.js +1 -1
- package/useAxios.mjs +2 -2
- package/useChangeCase.cjs +0 -2
- package/useChangeCase.iife.js +94 -55
- package/useChangeCase.iife.min.js +1 -1
- package/useCookies.cjs +2 -8
- package/useCookies.iife.js +96 -61
- package/useCookies.iife.min.js +1 -1
- package/useDrauu.cjs +0 -2
- package/useDrauu.iife.js +94 -55
- package/useDrauu.iife.min.js +1 -1
- package/useFocusTrap/component.cjs +2 -4
- package/useFocusTrap/component.d.ts +13 -2
- package/useFocusTrap/component.mjs +2 -2
- package/useFocusTrap.cjs +0 -2
- package/useFocusTrap.iife.js +94 -55
- package/useFocusTrap.iife.min.js +1 -1
- package/useFuse.cjs +1 -7
- package/useFuse.iife.js +95 -60
- package/useFuse.iife.min.js +1 -1
- package/useJwt.cjs +1 -7
- package/useJwt.iife.js +95 -60
- package/useJwt.iife.min.js +1 -1
- package/useNProgress.cjs +10 -16
- package/useNProgress.iife.js +104 -69
- package/useNProgress.iife.min.js +1 -1
- package/useQRCode.cjs +1 -7
- package/useQRCode.iife.js +95 -60
- package/useQRCode.iife.min.js +1 -1
package/useAsyncValidator.cjs
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var shared = require('@vueuse/shared');
|
|
6
4
|
var Schema = require('async-validator');
|
|
7
5
|
var vueDemi = require('vue-demi');
|
|
8
6
|
|
|
9
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
-
|
|
11
|
-
var Schema__default = /*#__PURE__*/_interopDefaultLegacy(Schema);
|
|
12
|
-
|
|
13
7
|
var __defProp = Object.defineProperty;
|
|
14
8
|
var __defProps = Object.defineProperties;
|
|
15
9
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -45,7 +39,7 @@ function useAsyncValidator(value, rules, options = {}) {
|
|
|
45
39
|
vueDemi.watchEffect(async () => {
|
|
46
40
|
isFinished.value = false;
|
|
47
41
|
pass.value = false;
|
|
48
|
-
const validator = new
|
|
42
|
+
const validator = new Schema(shared.resolveUnref(rules));
|
|
49
43
|
try {
|
|
50
44
|
await validator.validate(shared.resolveUnref(value), validateOption);
|
|
51
45
|
pass.value = true;
|
|
@@ -1,83 +1,120 @@
|
|
|
1
|
-
|
|
1
|
+
var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
|
|
2
2
|
if (VueDemi.install) {
|
|
3
3
|
return VueDemi
|
|
4
4
|
}
|
|
5
|
-
if (Vue) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
if (!Vue) {
|
|
6
|
+
console.error('[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.')
|
|
7
|
+
return VueDemi
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Vue 2.7
|
|
11
|
+
if (Vue.version.slice(0, 4) === '2.7.') {
|
|
12
|
+
for (var key in Vue) {
|
|
13
|
+
VueDemi[key] = Vue[key]
|
|
14
|
+
}
|
|
15
|
+
VueDemi.isVue2 = true
|
|
16
|
+
VueDemi.isVue3 = false
|
|
17
|
+
VueDemi.install = function () {}
|
|
18
|
+
VueDemi.Vue = Vue
|
|
19
|
+
VueDemi.Vue2 = Vue
|
|
20
|
+
VueDemi.version = Vue.version
|
|
21
|
+
VueDemi.warn = Vue.util.warn
|
|
22
|
+
function createApp(rootComponent, rootProps) {
|
|
23
|
+
var vm
|
|
24
|
+
var provide = {}
|
|
25
|
+
var app = {
|
|
26
|
+
config: Vue.config,
|
|
27
|
+
use: Vue.use.bind(Vue),
|
|
28
|
+
mixin: Vue.mixin.bind(Vue),
|
|
29
|
+
component: Vue.component.bind(Vue),
|
|
30
|
+
provide: function (key, value) {
|
|
31
|
+
provide[key] = value
|
|
32
|
+
return this
|
|
33
|
+
},
|
|
34
|
+
directive: function (name, dir) {
|
|
35
|
+
if (dir) {
|
|
36
|
+
Vue.directive(name, dir)
|
|
37
|
+
return app
|
|
38
|
+
} else {
|
|
39
|
+
return Vue.directive(name)
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
mount: function (el, hydrating) {
|
|
43
|
+
if (!vm) {
|
|
44
|
+
vm = new Vue(Object.assign({ propsData: rootProps }, rootComponent, { provide: Object.assign(provide, rootComponent.provide) }))
|
|
45
|
+
vm.$mount(el, hydrating)
|
|
46
|
+
return vm
|
|
47
|
+
} else {
|
|
48
|
+
return vm
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
unmount: function () {
|
|
52
|
+
if (vm) {
|
|
53
|
+
vm.$destroy()
|
|
54
|
+
vm = undefined
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
return app
|
|
59
|
+
}
|
|
60
|
+
VueDemi.createApp = createApp
|
|
61
|
+
}
|
|
62
|
+
// Vue 2.6.x
|
|
63
|
+
else if (Vue.version.slice(0, 2) === '2.') {
|
|
64
|
+
if (VueCompositionAPI) {
|
|
65
|
+
for (var key in VueCompositionAPI) {
|
|
66
|
+
VueDemi[key] = VueCompositionAPI[key]
|
|
9
67
|
}
|
|
10
68
|
VueDemi.isVue2 = true
|
|
11
69
|
VueDemi.isVue3 = false
|
|
12
|
-
VueDemi.install = function (){}
|
|
70
|
+
VueDemi.install = function () {}
|
|
13
71
|
VueDemi.Vue = Vue
|
|
14
72
|
VueDemi.Vue2 = Vue
|
|
15
73
|
VueDemi.version = Vue.version
|
|
74
|
+
} else {
|
|
75
|
+
console.error('[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.')
|
|
16
76
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
} else if (Vue.version.slice(0, 2) === '3.') {
|
|
34
|
-
for (var key in Vue) {
|
|
35
|
-
VueDemi[key] = Vue[key]
|
|
36
|
-
}
|
|
37
|
-
VueDemi.isVue2 = false
|
|
38
|
-
VueDemi.isVue3 = true
|
|
39
|
-
VueDemi.install = function (){}
|
|
40
|
-
VueDemi.Vue = Vue
|
|
41
|
-
VueDemi.Vue2 = undefined
|
|
42
|
-
VueDemi.version = Vue.version
|
|
43
|
-
VueDemi.set = function(target, key, val) {
|
|
44
|
-
if (Array.isArray(target)) {
|
|
45
|
-
target.length = Math.max(target.length, key)
|
|
46
|
-
target.splice(key, 1, val)
|
|
47
|
-
return val
|
|
48
|
-
}
|
|
49
|
-
target[key] = val
|
|
77
|
+
}
|
|
78
|
+
// Vue 3
|
|
79
|
+
else if (Vue.version.slice(0, 2) === '3.') {
|
|
80
|
+
for (var key in Vue) {
|
|
81
|
+
VueDemi[key] = Vue[key]
|
|
82
|
+
}
|
|
83
|
+
VueDemi.isVue2 = false
|
|
84
|
+
VueDemi.isVue3 = true
|
|
85
|
+
VueDemi.install = function () {}
|
|
86
|
+
VueDemi.Vue = Vue
|
|
87
|
+
VueDemi.Vue2 = undefined
|
|
88
|
+
VueDemi.version = Vue.version
|
|
89
|
+
VueDemi.set = function (target, key, val) {
|
|
90
|
+
if (Array.isArray(target)) {
|
|
91
|
+
target.length = Math.max(target.length, key)
|
|
92
|
+
target.splice(key, 1, val)
|
|
50
93
|
return val
|
|
51
94
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
95
|
+
target[key] = val
|
|
96
|
+
return val
|
|
97
|
+
}
|
|
98
|
+
VueDemi.del = function (target, key) {
|
|
99
|
+
if (Array.isArray(target)) {
|
|
100
|
+
target.splice(key, 1)
|
|
101
|
+
return
|
|
58
102
|
}
|
|
59
|
-
|
|
60
|
-
console.error('[vue-demi] Vue version ' + Vue.version + ' is unsupported.')
|
|
103
|
+
delete target[key]
|
|
61
104
|
}
|
|
62
105
|
} else {
|
|
63
|
-
console.error(
|
|
64
|
-
'[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.'
|
|
65
|
-
)
|
|
106
|
+
console.error('[vue-demi] Vue version ' + Vue.version + ' is unsupported.')
|
|
66
107
|
}
|
|
67
108
|
return VueDemi
|
|
68
109
|
})(
|
|
69
|
-
this.VueDemi = this.VueDemi || (typeof VueDemi !==
|
|
70
|
-
this.Vue || (typeof Vue !==
|
|
71
|
-
this.VueCompositionAPI || (typeof VueCompositionAPI !==
|
|
110
|
+
(this.VueDemi = this.VueDemi || (typeof VueDemi !== 'undefined' ? VueDemi : {})),
|
|
111
|
+
this.Vue || (typeof Vue !== 'undefined' ? Vue : undefined),
|
|
112
|
+
this.VueCompositionAPI || (typeof VueCompositionAPI !== 'undefined' ? VueCompositionAPI : undefined)
|
|
72
113
|
);
|
|
73
114
|
;
|
|
74
115
|
;(function (exports, shared, Schema, vueDemi) {
|
|
75
116
|
'use strict';
|
|
76
117
|
|
|
77
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
78
|
-
|
|
79
|
-
var Schema__default = /*#__PURE__*/_interopDefaultLegacy(Schema);
|
|
80
|
-
|
|
81
118
|
var __defProp = Object.defineProperty;
|
|
82
119
|
var __defProps = Object.defineProperties;
|
|
83
120
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -113,7 +150,7 @@
|
|
|
113
150
|
vueDemi.watchEffect(async () => {
|
|
114
151
|
isFinished.value = false;
|
|
115
152
|
pass.value = false;
|
|
116
|
-
const validator = new
|
|
153
|
+
const validator = new Schema(shared.resolveUnref(rules));
|
|
117
154
|
try {
|
|
118
155
|
await validator.validate(shared.resolveUnref(value), validateOption);
|
|
119
156
|
pass.value = true;
|
|
@@ -145,6 +182,4 @@
|
|
|
145
182
|
|
|
146
183
|
exports.useAsyncValidator = useAsyncValidator;
|
|
147
184
|
|
|
148
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
149
|
-
|
|
150
185
|
})(this.VueUse = this.VueUse || {}, VueUse, AsyncValidator, VueDemi);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var VueDemi=function(
|
|
1
|
+
var VueDemi=function(n,r,v){if(n.install)return n;if(!r)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),n;if(r.version.slice(0,4)==="2.7."){let o=function(i,c){var f,y={},p={config:r.config,use:r.use.bind(r),mixin:r.mixin.bind(r),component:r.component.bind(r),provide:function(u,d){return y[u]=d,this},directive:function(u,d){return d?(r.directive(u,d),p):r.directive(u)},mount:function(u,d){return f||(f=new r(Object.assign({propsData:c},i,{provide:Object.assign(y,i.provide)})),f.$mount(u,d),f)},unmount:function(){f&&(f.$destroy(),f=void 0)}};return p};var b=o;for(var e in r)n[e]=r[e];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=r,n.Vue2=r,n.version=r.version,n.warn=r.util.warn,n.createApp=o}else if(r.version.slice(0,2)==="2.")if(v){for(var e in v)n[e]=v[e];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=r,n.Vue2=r,n.version=r.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(r.version.slice(0,2)==="3."){for(var e in r)n[e]=r[e];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=r,n.Vue2=void 0,n.version=r.version,n.set=function(o,i,c){return Array.isArray(o)?(o.length=Math.max(o.length,i),o.splice(i,1,c),c):(o[i]=c,c)},n.del=function(o,i){if(Array.isArray(o)){o.splice(i,1);return}delete o[i]}}else console.error("[vue-demi] Vue version "+r.version+" is unsupported.");return n}(this.VueDemi=this.VueDemi||(typeof VueDemi!="undefined"?VueDemi:{}),this.Vue||(typeof Vue!="undefined"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI!="undefined"?VueCompositionAPI:void 0));(function(n,r,v,e){"use strict";var b=Object.defineProperty,o=Object.defineProperties,i=Object.getOwnPropertyDescriptors,c=Object.getOwnPropertySymbols,f=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable,p=(a,t,s)=>t in a?b(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s,u=(a,t)=>{for(var s in t||(t={}))f.call(t,s)&&p(a,s,t[s]);if(c)for(var s of c(t))y.call(t,s)&&p(a,s,t[s]);return a},d=(a,t)=>o(a,i(t));function A(a,t,s={}){const _=e.ref(),w=e.ref(!1),O=e.ref(!1),j=e.computed(()=>{var l;return((l=_.value)==null?void 0:l.errors)||[]}),U=e.computed(()=>{var l;return((l=_.value)==null?void 0:l.fields)||{}}),{validateOption:g={}}=s;e.watchEffect(async()=>{w.value=!1,O.value=!1;const l=new v(r.resolveUnref(t));try{await l.validate(r.resolveUnref(a),g),O.value=!0,_.value=null}catch(h){_.value=h}finally{w.value=!0}});const P={pass:O,isFinished:w,errorInfo:_,errors:j,errorFields:U};function I(){return new Promise((l,h)=>{r.until(w).toBe(!0).then(()=>l(P)).catch(x=>h(x))})}return d(u({},P),{then(l,h){return I().then(l,h)}})}n.useAsyncValidator=A})(this.VueUse=this.VueUse||{},VueUse,AsyncValidator,VueDemi);
|
package/useAxios.cjs
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var vueDemi = require('vue-demi');
|
|
6
4
|
var shared = require('@vueuse/shared');
|
|
7
5
|
var axios = require('axios');
|
|
8
6
|
|
|
9
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
-
|
|
11
|
-
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
12
|
-
|
|
13
7
|
var __defProp = Object.defineProperty;
|
|
14
8
|
var __defProps = Object.defineProperties;
|
|
15
9
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -33,8 +27,8 @@ function useAxios(...args) {
|
|
|
33
27
|
const url = typeof args[0] === "string" ? args[0] : void 0;
|
|
34
28
|
const argsPlaceholder = shared.isString(url) ? 1 : 0;
|
|
35
29
|
let defaultConfig = {};
|
|
36
|
-
let instance =
|
|
37
|
-
let options = { immediate: !!argsPlaceholder };
|
|
30
|
+
let instance = axios;
|
|
31
|
+
let options = { immediate: !!argsPlaceholder, shallow: true };
|
|
38
32
|
const isAxiosInstance = (val) => !!(val == null ? void 0 : val.request);
|
|
39
33
|
if (args.length > 0 + argsPlaceholder) {
|
|
40
34
|
if (isAxiosInstance(args[0 + argsPlaceholder]))
|
|
@@ -49,12 +43,12 @@ function useAxios(...args) {
|
|
|
49
43
|
if (args.length === 2 + argsPlaceholder && !isAxiosInstance(args[1 + argsPlaceholder]) || args.length === 3 + argsPlaceholder)
|
|
50
44
|
options = args[args.length - 1];
|
|
51
45
|
const response = vueDemi.shallowRef();
|
|
52
|
-
const data = vueDemi.shallowRef();
|
|
46
|
+
const data = options.shallow ? vueDemi.shallowRef() : vueDemi.ref();
|
|
53
47
|
const isFinished = vueDemi.ref(false);
|
|
54
48
|
const isLoading = vueDemi.ref(false);
|
|
55
49
|
const isAborted = vueDemi.ref(false);
|
|
56
50
|
const error = vueDemi.shallowRef();
|
|
57
|
-
const cancelToken =
|
|
51
|
+
const cancelToken = axios.CancelToken.source();
|
|
58
52
|
const abort = (message) => {
|
|
59
53
|
if (isFinished.value || !isLoading.value)
|
|
60
54
|
return;
|
package/useAxios.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ShallowRef, Ref } from 'vue-demi';
|
|
2
2
|
import { AxiosResponse, AxiosError, AxiosRequestConfig, AxiosInstance } from 'axios';
|
|
3
3
|
|
|
4
|
-
interface UseAxiosReturn<T> {
|
|
4
|
+
interface UseAxiosReturn<T, R = AxiosResponse<T>, D = any> {
|
|
5
5
|
/**
|
|
6
6
|
* Axios Response
|
|
7
7
|
*/
|
|
8
|
-
response: ShallowRef<
|
|
8
|
+
response: ShallowRef<R | undefined>;
|
|
9
9
|
/**
|
|
10
10
|
* Axios response data
|
|
11
11
|
*/
|
|
@@ -25,7 +25,7 @@ interface UseAxiosReturn<T> {
|
|
|
25
25
|
/**
|
|
26
26
|
* Any errors that may have occurred
|
|
27
27
|
*/
|
|
28
|
-
error: ShallowRef<AxiosError<T> | undefined>;
|
|
28
|
+
error: ShallowRef<AxiosError<T, D> | undefined>;
|
|
29
29
|
/**
|
|
30
30
|
* Aborts the current request
|
|
31
31
|
*/
|
|
@@ -59,17 +59,17 @@ interface UseAxiosReturn<T> {
|
|
|
59
59
|
*/
|
|
60
60
|
isCanceled: Ref<boolean>;
|
|
61
61
|
}
|
|
62
|
-
interface StrictUseAxiosReturn<T> extends UseAxiosReturn<T> {
|
|
62
|
+
interface StrictUseAxiosReturn<T, R, D> extends UseAxiosReturn<T, R, D> {
|
|
63
63
|
/**
|
|
64
64
|
* Manually call the axios request
|
|
65
65
|
*/
|
|
66
|
-
execute: (url?: string | AxiosRequestConfig
|
|
66
|
+
execute: (url?: string | AxiosRequestConfig<D>, config?: AxiosRequestConfig<D>) => PromiseLike<StrictUseAxiosReturn<T, R, D>>;
|
|
67
67
|
}
|
|
68
|
-
interface EasyUseAxiosReturn<T> extends UseAxiosReturn<T> {
|
|
68
|
+
interface EasyUseAxiosReturn<T, R, D> extends UseAxiosReturn<T, R, D> {
|
|
69
69
|
/**
|
|
70
70
|
* Manually call the axios request
|
|
71
71
|
*/
|
|
72
|
-
execute: (url: string, config?: AxiosRequestConfig) => PromiseLike<EasyUseAxiosReturn<T>>;
|
|
72
|
+
execute: (url: string, config?: AxiosRequestConfig<D>) => PromiseLike<EasyUseAxiosReturn<T, R, D>>;
|
|
73
73
|
}
|
|
74
74
|
interface UseAxiosOptions {
|
|
75
75
|
/**
|
|
@@ -77,12 +77,18 @@ interface UseAxiosOptions {
|
|
|
77
77
|
*
|
|
78
78
|
*/
|
|
79
79
|
immediate?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Use shallowRef.
|
|
82
|
+
*
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
shallow?: boolean;
|
|
80
86
|
}
|
|
81
|
-
declare function useAxios<T = any>(url: string, config?: AxiosRequestConfig
|
|
82
|
-
declare function useAxios<T = any>(url: string, instance?: AxiosInstance, options?: UseAxiosOptions): StrictUseAxiosReturn<T> & PromiseLike<StrictUseAxiosReturn<T>>;
|
|
83
|
-
declare function useAxios<T = any>(url: string, config: AxiosRequestConfig
|
|
84
|
-
declare function useAxios<T = any>(config?: AxiosRequestConfig): EasyUseAxiosReturn<T> & PromiseLike<EasyUseAxiosReturn<T>>;
|
|
85
|
-
declare function useAxios<T = any>(instance?: AxiosInstance): EasyUseAxiosReturn<T> & PromiseLike<EasyUseAxiosReturn<T>>;
|
|
86
|
-
declare function useAxios<T = any>(config?: AxiosRequestConfig
|
|
87
|
+
declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>, options?: UseAxiosOptions): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
|
|
88
|
+
declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, instance?: AxiosInstance, options?: UseAxiosOptions): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
|
|
89
|
+
declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, config: AxiosRequestConfig<D>, instance: AxiosInstance, options?: UseAxiosOptions): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
|
|
90
|
+
declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: AxiosRequestConfig<D>): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
|
|
91
|
+
declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(instance?: AxiosInstance): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
|
|
92
|
+
declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: AxiosRequestConfig<D>, instance?: AxiosInstance): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
|
|
87
93
|
|
|
88
94
|
export { EasyUseAxiosReturn, StrictUseAxiosReturn, UseAxiosOptions, UseAxiosReturn, useAxios };
|
package/useAxios.iife.js
CHANGED
|
@@ -1,83 +1,120 @@
|
|
|
1
|
-
|
|
1
|
+
var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
|
|
2
2
|
if (VueDemi.install) {
|
|
3
3
|
return VueDemi
|
|
4
4
|
}
|
|
5
|
-
if (Vue) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
if (!Vue) {
|
|
6
|
+
console.error('[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.')
|
|
7
|
+
return VueDemi
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Vue 2.7
|
|
11
|
+
if (Vue.version.slice(0, 4) === '2.7.') {
|
|
12
|
+
for (var key in Vue) {
|
|
13
|
+
VueDemi[key] = Vue[key]
|
|
14
|
+
}
|
|
15
|
+
VueDemi.isVue2 = true
|
|
16
|
+
VueDemi.isVue3 = false
|
|
17
|
+
VueDemi.install = function () {}
|
|
18
|
+
VueDemi.Vue = Vue
|
|
19
|
+
VueDemi.Vue2 = Vue
|
|
20
|
+
VueDemi.version = Vue.version
|
|
21
|
+
VueDemi.warn = Vue.util.warn
|
|
22
|
+
function createApp(rootComponent, rootProps) {
|
|
23
|
+
var vm
|
|
24
|
+
var provide = {}
|
|
25
|
+
var app = {
|
|
26
|
+
config: Vue.config,
|
|
27
|
+
use: Vue.use.bind(Vue),
|
|
28
|
+
mixin: Vue.mixin.bind(Vue),
|
|
29
|
+
component: Vue.component.bind(Vue),
|
|
30
|
+
provide: function (key, value) {
|
|
31
|
+
provide[key] = value
|
|
32
|
+
return this
|
|
33
|
+
},
|
|
34
|
+
directive: function (name, dir) {
|
|
35
|
+
if (dir) {
|
|
36
|
+
Vue.directive(name, dir)
|
|
37
|
+
return app
|
|
38
|
+
} else {
|
|
39
|
+
return Vue.directive(name)
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
mount: function (el, hydrating) {
|
|
43
|
+
if (!vm) {
|
|
44
|
+
vm = new Vue(Object.assign({ propsData: rootProps }, rootComponent, { provide: Object.assign(provide, rootComponent.provide) }))
|
|
45
|
+
vm.$mount(el, hydrating)
|
|
46
|
+
return vm
|
|
47
|
+
} else {
|
|
48
|
+
return vm
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
unmount: function () {
|
|
52
|
+
if (vm) {
|
|
53
|
+
vm.$destroy()
|
|
54
|
+
vm = undefined
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
return app
|
|
59
|
+
}
|
|
60
|
+
VueDemi.createApp = createApp
|
|
61
|
+
}
|
|
62
|
+
// Vue 2.6.x
|
|
63
|
+
else if (Vue.version.slice(0, 2) === '2.') {
|
|
64
|
+
if (VueCompositionAPI) {
|
|
65
|
+
for (var key in VueCompositionAPI) {
|
|
66
|
+
VueDemi[key] = VueCompositionAPI[key]
|
|
9
67
|
}
|
|
10
68
|
VueDemi.isVue2 = true
|
|
11
69
|
VueDemi.isVue3 = false
|
|
12
|
-
VueDemi.install = function (){}
|
|
70
|
+
VueDemi.install = function () {}
|
|
13
71
|
VueDemi.Vue = Vue
|
|
14
72
|
VueDemi.Vue2 = Vue
|
|
15
73
|
VueDemi.version = Vue.version
|
|
74
|
+
} else {
|
|
75
|
+
console.error('[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.')
|
|
16
76
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
} else if (Vue.version.slice(0, 2) === '3.') {
|
|
34
|
-
for (var key in Vue) {
|
|
35
|
-
VueDemi[key] = Vue[key]
|
|
36
|
-
}
|
|
37
|
-
VueDemi.isVue2 = false
|
|
38
|
-
VueDemi.isVue3 = true
|
|
39
|
-
VueDemi.install = function (){}
|
|
40
|
-
VueDemi.Vue = Vue
|
|
41
|
-
VueDemi.Vue2 = undefined
|
|
42
|
-
VueDemi.version = Vue.version
|
|
43
|
-
VueDemi.set = function(target, key, val) {
|
|
44
|
-
if (Array.isArray(target)) {
|
|
45
|
-
target.length = Math.max(target.length, key)
|
|
46
|
-
target.splice(key, 1, val)
|
|
47
|
-
return val
|
|
48
|
-
}
|
|
49
|
-
target[key] = val
|
|
77
|
+
}
|
|
78
|
+
// Vue 3
|
|
79
|
+
else if (Vue.version.slice(0, 2) === '3.') {
|
|
80
|
+
for (var key in Vue) {
|
|
81
|
+
VueDemi[key] = Vue[key]
|
|
82
|
+
}
|
|
83
|
+
VueDemi.isVue2 = false
|
|
84
|
+
VueDemi.isVue3 = true
|
|
85
|
+
VueDemi.install = function () {}
|
|
86
|
+
VueDemi.Vue = Vue
|
|
87
|
+
VueDemi.Vue2 = undefined
|
|
88
|
+
VueDemi.version = Vue.version
|
|
89
|
+
VueDemi.set = function (target, key, val) {
|
|
90
|
+
if (Array.isArray(target)) {
|
|
91
|
+
target.length = Math.max(target.length, key)
|
|
92
|
+
target.splice(key, 1, val)
|
|
50
93
|
return val
|
|
51
94
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
95
|
+
target[key] = val
|
|
96
|
+
return val
|
|
97
|
+
}
|
|
98
|
+
VueDemi.del = function (target, key) {
|
|
99
|
+
if (Array.isArray(target)) {
|
|
100
|
+
target.splice(key, 1)
|
|
101
|
+
return
|
|
58
102
|
}
|
|
59
|
-
|
|
60
|
-
console.error('[vue-demi] Vue version ' + Vue.version + ' is unsupported.')
|
|
103
|
+
delete target[key]
|
|
61
104
|
}
|
|
62
105
|
} else {
|
|
63
|
-
console.error(
|
|
64
|
-
'[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.'
|
|
65
|
-
)
|
|
106
|
+
console.error('[vue-demi] Vue version ' + Vue.version + ' is unsupported.')
|
|
66
107
|
}
|
|
67
108
|
return VueDemi
|
|
68
109
|
})(
|
|
69
|
-
this.VueDemi = this.VueDemi || (typeof VueDemi !==
|
|
70
|
-
this.Vue || (typeof Vue !==
|
|
71
|
-
this.VueCompositionAPI || (typeof VueCompositionAPI !==
|
|
110
|
+
(this.VueDemi = this.VueDemi || (typeof VueDemi !== 'undefined' ? VueDemi : {})),
|
|
111
|
+
this.Vue || (typeof Vue !== 'undefined' ? Vue : undefined),
|
|
112
|
+
this.VueCompositionAPI || (typeof VueCompositionAPI !== 'undefined' ? VueCompositionAPI : undefined)
|
|
72
113
|
);
|
|
73
114
|
;
|
|
74
115
|
;(function (exports, vueDemi, shared, axios) {
|
|
75
116
|
'use strict';
|
|
76
117
|
|
|
77
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
78
|
-
|
|
79
|
-
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
80
|
-
|
|
81
118
|
var __defProp = Object.defineProperty;
|
|
82
119
|
var __defProps = Object.defineProperties;
|
|
83
120
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -101,8 +138,8 @@
|
|
|
101
138
|
const url = typeof args[0] === "string" ? args[0] : void 0;
|
|
102
139
|
const argsPlaceholder = shared.isString(url) ? 1 : 0;
|
|
103
140
|
let defaultConfig = {};
|
|
104
|
-
let instance =
|
|
105
|
-
let options = { immediate: !!argsPlaceholder };
|
|
141
|
+
let instance = axios;
|
|
142
|
+
let options = { immediate: !!argsPlaceholder, shallow: true };
|
|
106
143
|
const isAxiosInstance = (val) => !!(val == null ? void 0 : val.request);
|
|
107
144
|
if (args.length > 0 + argsPlaceholder) {
|
|
108
145
|
if (isAxiosInstance(args[0 + argsPlaceholder]))
|
|
@@ -117,12 +154,12 @@
|
|
|
117
154
|
if (args.length === 2 + argsPlaceholder && !isAxiosInstance(args[1 + argsPlaceholder]) || args.length === 3 + argsPlaceholder)
|
|
118
155
|
options = args[args.length - 1];
|
|
119
156
|
const response = vueDemi.shallowRef();
|
|
120
|
-
const data = vueDemi.shallowRef();
|
|
157
|
+
const data = options.shallow ? vueDemi.shallowRef() : vueDemi.ref();
|
|
121
158
|
const isFinished = vueDemi.ref(false);
|
|
122
159
|
const isLoading = vueDemi.ref(false);
|
|
123
160
|
const isAborted = vueDemi.ref(false);
|
|
124
161
|
const error = vueDemi.shallowRef();
|
|
125
|
-
const cancelToken =
|
|
162
|
+
const cancelToken = axios.CancelToken.source();
|
|
126
163
|
const abort = (message) => {
|
|
127
164
|
if (isFinished.value || !isLoading.value)
|
|
128
165
|
return;
|
|
@@ -176,6 +213,4 @@
|
|
|
176
213
|
|
|
177
214
|
exports.useAxios = useAxios;
|
|
178
215
|
|
|
179
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
180
|
-
|
|
181
216
|
})(this.VueUse = this.VueUse || {}, VueDemi, VueUse, axios);
|
package/useAxios.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VueDemi=function(n,
|
|
1
|
+
var VueDemi=function(e,n,p){if(e.install)return e;if(!n)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),e;if(n.version.slice(0,4)==="2.7."){let s=function(f,d){var c,y={},h={config:n.config,use:n.use.bind(n),mixin:n.mixin.bind(n),component:n.component.bind(n),provide:function(a,u){return y[a]=u,this},directive:function(a,u){return u?(n.directive(a,u),h):n.directive(a)},mount:function(a,u){return c||(c=new n(Object.assign({propsData:d},f,{provide:Object.assign(y,f.provide)})),c.$mount(a,u),c)},unmount:function(){c&&(c.$destroy(),c=void 0)}};return h};var q=s;for(var l in n)e[l]=n[l];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=n,e.Vue2=n,e.version=n.version,e.warn=n.util.warn,e.createApp=s}else if(n.version.slice(0,2)==="2.")if(p){for(var l in p)e[l]=p[l];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=n,e.Vue2=n,e.version=n.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(n.version.slice(0,2)==="3."){for(var l in n)e[l]=n[l];e.isVue2=!1,e.isVue3=!0,e.install=function(){},e.Vue=n,e.Vue2=void 0,e.version=n.version,e.set=function(s,f,d){return Array.isArray(s)?(s.length=Math.max(s.length,f),s.splice(f,1,d),d):(s[f]=d,d)},e.del=function(s,f){if(Array.isArray(s)){s.splice(f,1);return}delete s[f]}}else console.error("[vue-demi] Vue version "+n.version+" is unsupported.");return e}(this.VueDemi=this.VueDemi||(typeof VueDemi!="undefined"?VueDemi:{}),this.Vue||(typeof Vue!="undefined"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI!="undefined"?VueCompositionAPI:void 0));(function(e,n,p,l){"use strict";var q=Object.defineProperty,s=Object.defineProperties,f=Object.getOwnPropertyDescriptors,d=Object.getOwnPropertySymbols,c=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable,h=(t,r,o)=>r in t?q(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o,a=(t,r)=>{for(var o in r||(r={}))c.call(r,o)&&h(t,o,r[o]);if(d)for(var o of d(r))y.call(r,o)&&h(t,o,r[o]);return t},u=(t,r)=>s(t,f(r));function B(...t){const r=typeof t[0]=="string"?t[0]:void 0,o=p.isString(r)?1:0;let g={},O=l,A={immediate:!!o,shallow:!0};const j=i=>!!(i==null?void 0:i.request);t.length>0+o&&(j(t[0+o])?O=t[0+o]:g=t[0+o]),t.length>1+o&&j(t[1+o])&&(O=t[1+o]),(t.length===2+o&&!j(t[1+o])||t.length===3+o)&&(A=t[t.length-1]);const x=n.shallowRef(),C=A.shallow?n.shallowRef():n.ref(),v=n.ref(!1),_=n.ref(!1),b=n.ref(!1),I=n.shallowRef(),R=l.CancelToken.source(),S=i=>{v.value||!_.value||(R.cancel(i),b.value=!0,_.value=!1,v.value=!1)},T=i=>{_.value=i,v.value=!i},L=()=>new Promise((i,w)=>{p.until(v).toBe(!0).then(()=>i($)).catch(w)}),E=(i,w)=>L().then(i,w),F=(i=r,w={})=>{I.value=void 0;const M=typeof i=="string"?i:r??"";return T(!0),O(M,u(a(a({},g),typeof i=="object"?i:w),{cancelToken:R.token})).then(P=>{x.value=P,C.value=P.data}).catch(P=>{I.value=P}).finally(()=>T(!1)),{then:E}};A.immediate&&r&&F();const $={response:x,data:C,error:I,finished:v,loading:_,isFinished:v,isLoading:_,cancel:S,isAborted:b,canceled:b,aborted:b,isCanceled:b,abort:S,execute:F};return u(a({},$),{then:E})}e.useAxios=B})(this.VueUse=this.VueUse||{},VueDemi,VueUse,axios);
|
package/useAxios.mjs
CHANGED
|
@@ -26,7 +26,7 @@ function useAxios(...args) {
|
|
|
26
26
|
const argsPlaceholder = isString(url) ? 1 : 0;
|
|
27
27
|
let defaultConfig = {};
|
|
28
28
|
let instance = axios;
|
|
29
|
-
let options = { immediate: !!argsPlaceholder };
|
|
29
|
+
let options = { immediate: !!argsPlaceholder, shallow: true };
|
|
30
30
|
const isAxiosInstance = (val) => !!(val == null ? void 0 : val.request);
|
|
31
31
|
if (args.length > 0 + argsPlaceholder) {
|
|
32
32
|
if (isAxiosInstance(args[0 + argsPlaceholder]))
|
|
@@ -41,7 +41,7 @@ function useAxios(...args) {
|
|
|
41
41
|
if (args.length === 2 + argsPlaceholder && !isAxiosInstance(args[1 + argsPlaceholder]) || args.length === 3 + argsPlaceholder)
|
|
42
42
|
options = args[args.length - 1];
|
|
43
43
|
const response = shallowRef();
|
|
44
|
-
const data = shallowRef();
|
|
44
|
+
const data = options.shallow ? shallowRef() : ref();
|
|
45
45
|
const isFinished = ref(false);
|
|
46
46
|
const isLoading = ref(false);
|
|
47
47
|
const isAborted = ref(false);
|