2 lines
3.4 KiB
JavaScript
2 lines
3.4 KiB
JavaScript
|
var VueDemi=function(e,n,v){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 i=function(c,u){var a,y={},w={config:n.config,use:n.use.bind(n),mixin:n.mixin.bind(n),component:n.component.bind(n),provide:function(f,p){return y[f]=p,this},directive:function(f,p){return p?(n.directive(f,p),w):n.directive(f)},mount:function(f,p){return a||(a=new n(Object.assign({propsData:u},c,{provide:Object.assign(y,c.provide)})),a.$mount(f,p),a)},unmount:function(){a&&(a.$destroy(),a=void 0)}};return w};var B=i;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=i}else if(n.version.slice(0,2)==="2.")if(v){for(var l in v)e[l]=v[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(i,c,u){return Array.isArray(i)?(i.length=Math.max(i.length,c),i.splice(c,1,u),u):(i[c]=u,u)},e.del=function(i,c){if(Array.isArray(i)){i.splice(c,1);return}delete i[c]}}else console.error("[vue-demi] Vue version "+n.version+" is unsupported.");return e}(this.VueDemi=this.VueDemi||(typeof VueDemi<"u"?VueDemi:{}),this.Vue||(typeof Vue<"u"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI<"u"?VueCompositionAPI:void 0));(function(e,n,v,l){"use strict";var B=Object.defineProperty,i=Object.defineProperties,c=Object.getOwnPropertyDescriptors,u=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable,w=(t,r,o)=>r in t?B(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o,f=(t,r)=>{for(var o in r||(r={}))a.call(r,o)&&w(t,o,r[o]);if(u)for(var o of u(r))y.call(r,o)&&w(t,o,r[o]);return t},p=(t,r)=>i(t,c(r));function M(...t){const r=typeof t[0]=="string"?t[0]:void 0,o=typeof r=="string"?1:0;let S={},A=l,b={immediate:!!o,shallow:!0};const j=s=>!!s?.request;t.length>0+o&&(j(t[0+o])?A=t[0+o]:S=t[0+o]),t.length>1+o&&j(t[1+o])&&(A=t[1+o]),(t.length===2+o&&!j(t[1+o])||t.length===3+o)&&(b=t[t.length-1]);const{initialData:T,shallow:z,onSuccess:G=v.noop,onError:H=v.noop,immediate:J,resetOnExecute:K=!1}=b,F=n.shallowRef(),E=(z?n.shallowRef:n.ref)(T),h=n.ref(!1),P=n.ref(!1),I=n.ref(!1),_=n.shallowRef(),L=l.CancelToken.source;let R=L();const x=s=>{h.value||!P.value||(R.cancel(s),R=L(),I.value=!0,P.value=!1,h.value=!1)},g=s=>{P.value=s,h.value=!s},Q=()=>{K&&(E.value=T)},N=()=>new Promise((s,O)=>{v.until(h).toBe(!0).then(()=>_.value?O(_.value):s($))}),C={then:(...s)=>N().then(...s),catch:(...s)=>N().catch(...s)},U=(s=r,O={})=>{_.value=void 0;const k=typeof s=="string"?s:r??O.url;return k===void 0?(_.value=new l.AxiosError(l.AxiosError.ERR_INVALID_URL),h.value=!0,C):(Q(),x(),g(!0),A(k,p(f(f({},S),typeof s=="object"?s:O),{cancelToken:R.token})).then(d=>{F.value=d;const q=d.data;E.value=q,G(q)}).catch(d=>{_.value=d,H(d)}).finally(()=>{var d;(d=b.onFinish)==null||d.call(b),g(!1)}),C)};J&&r&&U();const $={response:F,data:E,error:_,isFinished:h,isLoading:P,cancel:x,isAborted:I,isCanceled:I,abort:x,execute:U};return f(f({},$),C)}e.useAxios=M})(this.VueUse=this.VueUse||{},VueDemi,VueUse,axios);
|