Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-request

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-request - npm Package Compare versions

Comparing version 2.0.0-rc.1 to 2.0.0-rc.2

131

dist/index.cjs.js

@@ -528,2 +528,14 @@ 'use strict';

const composeMiddleware = (middleArray, hook) => {
return () => {
let next = hook;
for (let i = middleArray.length; i-- > 0;) {
next = middleArray[i](next);
}
return next();
};
};
const createQuery = (service, config, initialState) => {

@@ -544,4 +556,6 @@ var _initialState$loading, _initialState$data;

const plugins = vueDemi.ref([]);
const status = vueDemi.shallowRef('pending');
const context = {};
const setState = setStateBind({
status,
loading,

@@ -554,9 +568,16 @@ data,

const emit = (event, ...args) => {
// @ts-ignore
const res = plugins.value.map(i => {
var _i$event;
if (event === 'onQuery') {
const queryFn = plugins.value.map(i => i.onQuery).filter(Boolean);
return {
servicePromise: composeMiddleware(queryFn, args[0])()
};
} else {
// @ts-ignore
const res = plugins.value.map(i => {
var _i$event;
return (_i$event = i[event]) === null || _i$event === void 0 ? void 0 : _i$event.call(i, ...args);
});
return Object.assign({}, ...res);
return (_i$event = i[event]) === null || _i$event === void 0 ? void 0 : _i$event.call(i, ...args);
});
return Object.assign({}, ...res);
}
};

@@ -569,3 +590,4 @@

loading: true,
params: args
params: args,
status: 'pending'
});

@@ -578,12 +600,22 @@ count.value += 1;

} = emit('onBefore', args);
if (isBreak) return breakResult;
if (isBreak) {
setState({
status: 'settled'
});
return breakResult;
}
onBefore === null || onBefore === void 0 ? void 0 : onBefore(args);
try {
const serviceWrapper = () => new Promise(resolve => resolve(service(...params.value)));
let {
servicePromise
} = emit('onQuery', service, params.value);
} = emit('onQuery', serviceWrapper);
/* istanbul ignore next */
if (!servicePromise) {
servicePromise = service(...params.value);
servicePromise = serviceWrapper();
}

@@ -596,3 +628,4 @@

loading: false,
error: undefined
error: undefined,
status: 'settled'
});

@@ -608,3 +641,4 @@ emit('onSuccess', res, args);

loading: false,
error: error
error: error,
status: 'settled'
});

@@ -655,2 +689,3 @@ emit('onError', error, args);

return {
status,
loading,

@@ -943,3 +978,5 @@ data,

onQuery(service, params) {
onQuery(service) {
const params = queryInstance.params.value;
const _cacheKey = cacheKey(params);

@@ -950,13 +987,9 @@

if (servicePromise && servicePromise !== currentQuery) {
return {
servicePromise
};
return () => servicePromise;
}
servicePromise = service(...params);
servicePromise = service();
currentQuery = servicePromise;
setCacheQuery(_cacheKey, servicePromise);
return {
servicePromise
};
return () => servicePromise;
},

@@ -999,7 +1032,36 @@

function setTimeoutPromise(duration) {
let timerId, stop;
class Timer extends Promise {
constructor(fn) {
super(fn);
this.cancel = () => {
stop();
clearTimeout(timerId);
};
}
}
return new Timer(resolve => {
stop = resolve;
timerId = setTimeout(stop, duration);
});
}
function getCurrentTime() {
return new Date().getTime();
}
var useLoadingDelayPlugin = definePlugin((queryInstance, {
loadingDelay = 0
loadingDelay = 0,
loadingKeep = 0
}) => {
const delayLoadingTimer = vueDemi.ref(() => {});
const loadingDelayRef = vueDemi.computed(() => refToRaw(loadingDelay));
const loadingKeepRef = vueDemi.computed(() => refToRaw(loadingKeep));
let startTime = getCurrentTime();
let timeoutPromise = {};

@@ -1011,3 +1073,5 @@ const delayLoading = () => {

timerId = setTimeout(() => {
queryInstance.loading.value = true;
if (queryInstance.status.value === 'pending') {
queryInstance.loading.value = true;
}
}, loadingDelayRef.value);

@@ -1024,4 +1088,24 @@ }

delayLoadingTimer.value = delayLoading();
startTime = getCurrentTime();
},
onQuery(service) {
if (!loadingKeepRef.value) return () => service();
timeoutPromise = setTimeoutPromise(loadingKeepRef.value + loadingDelayRef.value);
const servicePromise = Promise.allSettled([service().finally(() => {
if (getCurrentTime() - startTime <= loadingDelayRef.value) {
timeoutPromise.cancel();
}
}), timeoutPromise]).then(res => {
const result = res[0];
if (result.status === 'fulfilled') {
return result.value;
} else {
return Promise.reject(result.reason);
}
});
return () => servicePromise;
},
onCancel() {

@@ -1217,3 +1301,4 @@ delayLoadingTimer.value();

function useRequest(service, options) {
return useQuery(service, options, [useLoadingDelayPlugin, useErrorRetryPlugin, useDebouncePlugin, usePollingPlugin, useThrottlePlugin, useRefreshOnWindowFocus, useRefreshDepsPlugin, useReadyPlugin, useCachePlugin]);
return useQuery(service, options, [useLoadingDelayPlugin, // useLoadingKeepPlugin,
useErrorRetryPlugin, useDebouncePlugin, usePollingPlugin, useThrottlePlugin, useRefreshOnWindowFocus, useRefreshDepsPlugin, useReadyPlugin, useCachePlugin]);
}

@@ -1220,0 +1305,0 @@

@@ -524,2 +524,14 @@ import { isRef, ref, computed, watchEffect, watch, shallowRef, inject, onUnmounted, provide } from 'vue-demi';

const composeMiddleware = (middleArray, hook) => {
return () => {
let next = hook;
for (let i = middleArray.length; i-- > 0;) {
next = middleArray[i](next);
}
return next();
};
};
const createQuery = (service, config, initialState) => {

@@ -540,4 +552,6 @@ var _initialState$loading, _initialState$data;

const plugins = ref([]);
const status = shallowRef('pending');
const context = {};
const setState = setStateBind({
status,
loading,

@@ -550,9 +564,16 @@ data,

const emit = (event, ...args) => {
// @ts-ignore
const res = plugins.value.map(i => {
var _i$event;
if (event === 'onQuery') {
const queryFn = plugins.value.map(i => i.onQuery).filter(Boolean);
return {
servicePromise: composeMiddleware(queryFn, args[0])()
};
} else {
// @ts-ignore
const res = plugins.value.map(i => {
var _i$event;
return (_i$event = i[event]) === null || _i$event === void 0 ? void 0 : _i$event.call(i, ...args);
});
return Object.assign({}, ...res);
return (_i$event = i[event]) === null || _i$event === void 0 ? void 0 : _i$event.call(i, ...args);
});
return Object.assign({}, ...res);
}
};

@@ -565,3 +586,4 @@

loading: true,
params: args
params: args,
status: 'pending'
});

@@ -574,12 +596,22 @@ count.value += 1;

} = emit('onBefore', args);
if (isBreak) return breakResult;
if (isBreak) {
setState({
status: 'settled'
});
return breakResult;
}
onBefore === null || onBefore === void 0 ? void 0 : onBefore(args);
try {
const serviceWrapper = () => new Promise(resolve => resolve(service(...params.value)));
let {
servicePromise
} = emit('onQuery', service, params.value);
} = emit('onQuery', serviceWrapper);
/* istanbul ignore next */
if (!servicePromise) {
servicePromise = service(...params.value);
servicePromise = serviceWrapper();
}

@@ -592,3 +624,4 @@

loading: false,
error: undefined
error: undefined,
status: 'settled'
});

@@ -604,3 +637,4 @@ emit('onSuccess', res, args);

loading: false,
error: error
error: error,
status: 'settled'
});

@@ -651,2 +685,3 @@ emit('onError', error, args);

return {
status,
loading,

@@ -939,3 +974,5 @@ data,

onQuery(service, params) {
onQuery(service) {
const params = queryInstance.params.value;
const _cacheKey = cacheKey(params);

@@ -946,13 +983,9 @@

if (servicePromise && servicePromise !== currentQuery) {
return {
servicePromise
};
return () => servicePromise;
}
servicePromise = service(...params);
servicePromise = service();
currentQuery = servicePromise;
setCacheQuery(_cacheKey, servicePromise);
return {
servicePromise
};
return () => servicePromise;
},

@@ -995,7 +1028,36 @@

function setTimeoutPromise(duration) {
let timerId, stop;
class Timer extends Promise {
constructor(fn) {
super(fn);
this.cancel = () => {
stop();
clearTimeout(timerId);
};
}
}
return new Timer(resolve => {
stop = resolve;
timerId = setTimeout(stop, duration);
});
}
function getCurrentTime() {
return new Date().getTime();
}
var useLoadingDelayPlugin = definePlugin((queryInstance, {
loadingDelay = 0
loadingDelay = 0,
loadingKeep = 0
}) => {
const delayLoadingTimer = ref(() => {});
const loadingDelayRef = computed(() => refToRaw(loadingDelay));
const loadingKeepRef = computed(() => refToRaw(loadingKeep));
let startTime = getCurrentTime();
let timeoutPromise = {};

@@ -1007,3 +1069,5 @@ const delayLoading = () => {

timerId = setTimeout(() => {
queryInstance.loading.value = true;
if (queryInstance.status.value === 'pending') {
queryInstance.loading.value = true;
}
}, loadingDelayRef.value);

@@ -1020,4 +1084,24 @@ }

delayLoadingTimer.value = delayLoading();
startTime = getCurrentTime();
},
onQuery(service) {
if (!loadingKeepRef.value) return () => service();
timeoutPromise = setTimeoutPromise(loadingKeepRef.value + loadingDelayRef.value);
const servicePromise = Promise.allSettled([service().finally(() => {
if (getCurrentTime() - startTime <= loadingDelayRef.value) {
timeoutPromise.cancel();
}
}), timeoutPromise]).then(res => {
const result = res[0];
if (result.status === 'fulfilled') {
return result.value;
} else {
return Promise.reject(result.reason);
}
});
return () => servicePromise;
},
onCancel() {

@@ -1213,3 +1297,4 @@ delayLoadingTimer.value();

function useRequest(service, options) {
return useQuery(service, options, [useLoadingDelayPlugin, useErrorRetryPlugin, useDebouncePlugin, usePollingPlugin, useThrottlePlugin, useRefreshOnWindowFocus, useRefreshDepsPlugin, useReadyPlugin, useCachePlugin]);
return useQuery(service, options, [useLoadingDelayPlugin, // useLoadingKeepPlugin,
useErrorRetryPlugin, useDebouncePlugin, usePollingPlugin, useThrottlePlugin, useRefreshOnWindowFocus, useRefreshDepsPlugin, useReadyPlugin, useCachePlugin]);
}

@@ -1216,0 +1301,0 @@

3

dist/types/index.d.ts

@@ -62,2 +62,3 @@ import { WritableComputedRef, ComputedRef, Ref, WatchSource } from 'vue-demi';

loadingDelay?: number | Ref<number>;
loadingKeep?: number | Ref<number>;
pollingInterval?: number | Ref<number>;

@@ -120,2 +121,2 @@ pollingWhenHidden?: boolean;

export { Options, clearCache, setGlobalOptions, useLoadMore, usePagination, useRequest, _default as useRequestProvider };
export { DataType, LoadMoreBaseOptions, LoadMoreService, Options, PaginationOptions, Service, clearCache, setGlobalOptions, useLoadMore, usePagination, useRequest, _default as useRequestProvider };

@@ -1,1 +0,1 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("vue-demi")):"function"==typeof define&&define.amd?define(["exports","vue-demi"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).VueRequest=e.VueRequest||{},e.vueDemi)}(this,(function(e,n){"use strict";const t={},a=Symbol("GLOBAL_OPTIONS_PROVIDE_KEY"),r=()=>t,o=Object.prototype.toString,u=e=>"[object Object]"===(e=>o.call(e))(e),l=e=>null!==e&&"object"==typeof e,i=e=>e instanceof Function,c=e=>null==e,s="undefined"==typeof window,v=()=>{var e;return!(!s&&!c(null===(e=window.document)||void 0===e?void 0:e.visibilityState))||"visible"===window.document.visibilityState},d=()=>new Promise((()=>{})),f=(e,n,t)=>{const a=n.replace(/\[(\d+)\]/g,".$1").split(".");let r=e;for(const e of a)if(r=Object(r)[e],void 0===r)return t;return r};function m(e,n){const t=Object.assign({},e);for(const e of n)delete t[e];return t}const p=e=>n.isRef(e)?e.value:e,h=new Map;function g(e,n,t){let a,r,o,u,i,c,s=0,v=!1,d=!1,f=!0;const m=!n&&0!==n&&"function"==typeof window.requestAnimationFrame;if("function"!=typeof e)throw new TypeError("Expected a function");function p(n){const t=a,o=r;return a=r=void 0,s=n,u=e.apply(o,t),u}function h(e,n){return m?(window.cancelAnimationFrame(i),window.requestAnimationFrame(e)):setTimeout(e,n)}function g(e){const t=e-c;return void 0===c||t>=n||t<0||d&&e-s>=o}function y(){const e=Date.now();if(g(e))return w(e);i=h(y,function(e){const t=e-s,a=n-(e-c);return d?Math.min(a,o-t):a}(e))}function w(e){return i=void 0,f&&a?p(e):(a=r=void 0,u)}function E(...e){const t=Date.now(),o=g(t);if(a=e,r=this,c=t,o){if(void 0===i)return function(e){return s=e,i=h(y,n),v?p(e):u}(c);if(d)return i=h(y,n),p(c)}return void 0===i&&(i=h(y,n)),u}return n=+n||0,l(t)&&(v=!!t.leading,d="maxWait"in t,o=d?Math.max(+t.maxWait||0,n):o,f="trailing"in t?!!t.trailing:f),E.cancel=function(){void 0!==i&&function(e){if(m)return window.cancelAnimationFrame(e);clearTimeout(e)}(i),s=0,a=c=r=i=void 0},E.flush=function(){return void 0===i?u:w(Date.now())},E.pending=function(){return void 0!==i},E}function y(e,n){for(const a in n)void 0!==n[a]&&(l(n[a])&&l(e[a])&&a in e?(u(n[a])||(t=n[a],Array.isArray(t)))&&y(e[a],n[a]):e[a]=n[a]);var t}function w(e,...n){const t=Object.assign({},e);if(!n.length)return t;for(const e of n)y(t,e);return t}var E=(e,{debounceInterval:t,debounceOptions:a,manual:r})=>{const o=n.ref(!1),u=n.ref(),l=n.computed((()=>a)),i=n.computed((()=>p(t))),s=n.ref(e.context.runAsync);return r||(o.value=!0),n.watchEffect((n=>{c(i.value)||(u.value=g((e=>e()),i.value,l.value),e.context.runAsync=(...e)=>new Promise(((n,t)=>{o.value?(o.value=!1,s.value(...e).then(n).catch(t)):u.value((()=>{s.value(...e).then(n).catch(t)}))})),n((()=>{var n;null===(n=u.value)||void 0===n||n.cancel(),e.context.runAsync=s.value})))})),{onCancel(){var e;null===(e=u.value)||void 0===e||e.cancel()}}},A=(e,{errorRetryCount:t=0,errorRetryInterval:a=0})=>{const r=n.ref(),o=n.ref(0),u=n.computed((()=>p(t))),l=n.computed((()=>p(a)));let i=!1;const c=()=>{o.value=0},s=n.computed((()=>{if(l.value)return l.value;return 1e3*Math.floor(Math.random()*2**Math.min(o.value,9)+1)})),v=()=>{r.value&&r.value()};return{onBefore(){i||c(),i=!1,v()},onSuccess(){c()},onError(){r.value=(()=>{let n;const t=-1===u.value,a=o.value<u.value;return(t||a)&&(t||(o.value+=1),n=setTimeout((()=>{i=!0,e.context.refresh()}),s.value)),()=>n&&clearTimeout(n)})()},onCancel(){c(),v()}}},T=(e,{ready:t=n.ref(!0),manual:a,defaultParams:r=[]})=>(n.watch(t,(n=>{!a&&n&&e.context.run(...r)}),{flush:"sync"}),{onBefore(){if(!t.value)return e.loading.value=!1,{isBreak:!0}}}),x=(e,{refreshDeps:t=[],refreshDepsAction:a,manual:r})=>(null!=t&&t.length&&n.watch(t,(()=>{a?a():!r&&e.context.refresh()})),{}),b=(e,{throttleInterval:t,throttleOptions:a})=>{const r=n.ref(),o=n.computed((()=>p(t))),u=n.computed((()=>a)),i=n.ref(e.context.runAsync);return n.watchEffect((n=>{if(c(t))return{};r.value=function(e,n,t){let a=!0,r=!0;if("function"!=typeof e)throw new TypeError("Expected a function");return l(t)&&(a="leading"in t?!!t.leading:a,r="trailing"in t?!!t.trailing:r),g(e,n,{leading:a,trailing:r,maxWait:n})}((e=>e()),o.value,u.value),e.context.runAsync=(...e)=>new Promise(((n,t)=>{r.value((()=>{i.value(...e).then(n).catch(t)}))})),n((()=>{var n;null===(n=r.value)||void 0===n||n.cancel(),e.context.runAsync=i.value}))})),{onCancel(){var e;null===(e=r.value)||void 0===e||e.cancel()}}};const S=(e,t,a)=>{var r,o;const{initialData:u,onSuccess:c,onError:s,onBefore:v,onAfter:f}=t,m=n.ref(null!==(r=null==a?void 0:a.loading)&&void 0!==r&&r),p=n.shallowRef(null!==(o=null==a?void 0:a.data)&&void 0!==o?o:u),h=n.shallowRef(null==a?void 0:a.error),g=n.ref(null==a?void 0:a.params),y=n.ref([]),w={},E=(A={loading:m,data:p,error:h,params:g},T=[],e=>{Object.keys(e).forEach((n=>{A[n].value=e[n]})),T.forEach((e=>e(A)))});var A,T;const x=(e,...n)=>{const t=y.value.map((t=>{var a;return null===(a=t[e])||void 0===a?void 0:a.call(t,...n)}));return Object.assign({},...t)},b=n.ref(0);return w.runAsync=async(...n)=>{E({loading:!0,params:n}),b.value+=1;const t=b.value,{isBreak:a,breakResult:r=d()}=x("onBefore",n);if(a)return r;null==v||v(n);try{let{servicePromise:a}=x("onQuery",e,g.value);a||(a=e(...g.value));const r=await a;return t!==b.value?d():(E({data:r,loading:!1,error:void 0}),x("onSuccess",r,n),null==c||c(r,n),x("onAfter",n,r,void 0),null==f||f(n),r)}catch(e){if(t!==b.value)return d();throw E({loading:!1,error:e}),x("onError",e,n),null==s||s(e,n),x("onAfter",n,void 0,e),null==f||f(n),e}},w.run=async(...e)=>{w.runAsync(...e).catch((e=>{s||console.error(e)}))},w.cancel=()=>{b.value+=1,E({loading:!1}),x("onCancel")},w.refresh=()=>{w.run(...g.value||[])},w.refreshAsync=()=>w.runAsync(...g.value||[]),w.mutate=e=>{const n=i(e)?e(p.value):e,t=l(n)?Object.assign({},n):n;E({data:t}),x("onMutate",t)},{loading:m,data:p,error:h,params:g,plugins:y,context:w}};function O(e,t={},o){const u=n.inject(a,{}),l={...r(),...u,...t},{manual:i=!1,defaultParams:c=[]}=l,s=S(e,l);if(s.plugins.value=o.map((e=>e(s,l))),!i){const e=s.params.value||c;s.context.run(...e)}return n.onUnmounted((()=>{s.context.cancel()})),{loading:s.loading,data:s.data,error:s.error,params:s.params,cancel:s.context.cancel,refresh:s.context.refresh,refreshAsync:s.context.refreshAsync,mutate:s.context.mutate,run:s.context.run,runAsync:s.context.runAsync}}const P=new Map,R=new Map;var M,I=(e,{cacheKey:t,cacheTime:a=6e5,staleTime:r=0,getCache:o,setCache:u})=>{if(!t)return{};const l=i(t)?t:()=>t,s=n.ref((()=>{}));let v;const d=e=>o?o(e):(e=>{if(c(e))return;return h.get(e)})(e),f=(e,n,t)=>{u?u(e,t):((e,n,t)=>{const a=h.get(e);null!=a&&a.timer&&clearTimeout(a.timer);const r=setTimeout((()=>h.delete(e)),n);h.set(e,{...t,timer:r})})(e,n,t),((e,n)=>{R.has(e)&&R.get(e).forEach((e=>e(n)))})(e,t.data)},m=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),p=n=>{const t=l(n);return a=t,r=n=>{e.data.value=n},R.has(a)?R.get(a).push(r):R.set(a,[r]),()=>{const e=R.get(a).indexOf(r);R.get(a).splice(e,1)};var a,r},g=l(),y=d(g);return y&&m(y,"data")&&(e.data.value=y.data,e.params.value=y.params),g&&(s.value=p()),n.onUnmounted((()=>{s.value()})),{onBefore(n){const t=l(n),a=d(t);return a&&m(a,"data")?(o=a.time,-1===r||o+r>(new Date).getTime()?(e.data.value=a.data,e.loading.value=!1,{isBreak:!0,breakResult:a.data}):void(e.data.value=a.data)):{};var o},onQuery(e,n){const t=l(n);let a=(e=>P.get(e))(t);return a&&a!==v||(a=e(...n),v=a,((e,n)=>{P.set(e,n),n.then((n=>(P.delete(e),n))).catch((()=>{P.delete(e)}))})(t,a)),{servicePromise:a}},onSuccess(e,n){const t=l(n);t&&(s.value(),f(t,a,{data:e,params:n,time:(new Date).getTime()}),s.value=p(n))},onMutate(n){const t=l(e.params.value);t&&(s.value(),f(t,a,{data:n,params:e.params.value,time:(new Date).getTime()}),s.value=p(e.params.value))}}},L=(e,{loadingDelay:t=0})=>{const a=n.ref((()=>{})),r=n.computed((()=>p(t)));return{onBefore(){e.loading.value=!r.value,a.value(),a.value=(()=>{let n;return r.value&&(n=setTimeout((()=>{e.loading.value=!0}),r.value)),()=>n&&clearTimeout(n)})()},onCancel(){a.value()},onAfter(){a.value()}}};const j=new Set,C=new Set,B=new Set,D=(e,n)=>{let t;switch(e){case"FOCUS_LISTENER":t=j;break;case"RECONNECT_LISTENER":t=B;break;case"VISIBLE_LISTENER":t=C}if(!t.has(n))return t.add(n),()=>{t.delete(n)}},N=e=>{e.forEach((e=>{e()}))};!s&&null!==(M=window)&&void 0!==M&&M.addEventListener&&(window.addEventListener("visibilitychange",(()=>{v()&&N(C)}),!1),window.addEventListener("focus",(()=>N(j)),!1),window.addEventListener("online",(()=>N(B)),!1));var _=(e,{pollingInterval:t,pollingWhenHidden:a=!1,pollingWhenOffline:r=!1,errorRetryCount:o=0})=>{const u=n.ref(),l=n.ref(!1),i=n.computed((()=>p(t))),d=n.computed((()=>p(o))),f=[],m=e=>{e&&f.push(e)},h=()=>{return(a||v())&&(r||null===(e=!s&&(null===(n=window.navigator)||void 0===n?void 0:n.onLine))||void 0===e||e);var e,n},g=n=>{if(e.error.value&&0!==d.value)return;let t;if(!c(i.value)&&i.value>=0){if(!h())return void(l.value=!0);t=setTimeout(n,i.value)}return()=>t&&clearTimeout(t)},y=()=>{l.value&&h()&&(e.context.refresh(),l.value=!1)};return n.watch(i,(()=>{u.value&&(u.value(),u.value=g((()=>e.context.refresh())))})),a||m(D("VISIBLE_LISTENER",y)),r||m(D("RECONNECT_LISTENER",y)),n.onUnmounted((()=>{f.forEach((e=>e()))})),{onBefore(){var e;null===(e=u.value)||void 0===e||e.call(u)},onCancel(){var e;null===(e=u.value)||void 0===e||e.call(u)},onAfter(){u.value=g((()=>e.context.refresh()))}}};var k=(e,{refreshOnWindowFocus:t=!1,refocusTimespan:a=5e3})=>{const r=n.computed((()=>p(t))),o=n.computed((()=>p(a))),u=[],l=e=>{e&&u.push(e)},i=()=>{u.forEach((e=>e()))};return n.watchEffect((()=>{if(i(),r.value){const n=((e,n)=>{let t=!1;return(...a)=>{t||(t=!0,e(...a),setTimeout((()=>{t=!1}),n))}})(e.context.refresh,o.value);l(D("VISIBLE_LISTENER",n)),l(D("FOCUS_LISTENER",n))}})),n.onUnmounted((()=>{i()})),{}};function K(e,n){return O(e,n,[L,A,E,_,b,k,x,T,I])}e.clearCache=e=>{if(e){var n;const t=null===(n=h.get(e))||void 0===n?void 0:n.timer;t&&clearTimeout(t),h.delete(e)}else h.forEach((e=>e.timer&&clearTimeout(e.timer))),h.clear()},e.setGlobalOptions=e=>{Object.keys(e).forEach((n=>{t[n]=e[n]}))},e.useLoadMore=function(e,t){const{isNoMore:a,...r}=null!=t?t:{},o=n.shallowRef(),u=n.computed((()=>{var e;return(null===(e=o.value)||void 0===e?void 0:e.list)||[]})),c=n.ref(!1),s=n.ref(!1),v=n.ref(0),{runAsync:d,run:f,cancel:p,...h}=O((async n=>{const t=v.value,a=await e(n);return t===v.value&&(o.value=n?{...a,list:[...n.list,...a.list]}:a),a}),{...r,defaultParams:[],refreshDepsAction:()=>{null!=r&&r.refreshDepsAction?r.refreshDepsAction():w()},onError:e=>{var n;null==r||null===(n=r.onError)||void 0===n||n.call(r,e)},onSuccess:e=>{var n;null==r||null===(n=r.onSuccess)||void 0===n||n.call(r,e)},onBefore:()=>{var e;v.value+=1,s.value&&(s.value=!1,c.value=!0),null==r||null===(e=r.onBefore)||void 0===e||e.call(r)},onAfter:()=>{var e;c.value=!1,s.value=!1,null==r||null===(e=r.onAfter)||void 0===e||e.call(r)}},[A,E,b,x,T]),g=n.computed((()=>!(!a||!i(a))&&a(o.value))),y=()=>g.value?Promise.reject(((e,n=!1)=>{const t=`Warning: [vue-request] ${e}`;if(n)return new Error(t);console.error(t)})("No more data. You need to ignore this error by checking if `noMore` is false before calling `loadMoreAsync`",!0)):(s.value=!0,d(o.value)),w=()=>f();return{data:o,dataList:u,loadingMore:c,noMore:g,cancel:()=>{v.value+=1,p(),c.value=!1},mutate:e=>{const n=i(e)?e(o.value):e,t=l(n)?Object.assign({},n):n;o.value=t},refresh:w,refreshAsync:()=>d(),loadMore:()=>{y().catch((()=>{}))},loadMoreAsync:y,...m(h,["refresh","refreshAsync","mutate","params","data"])}},e.usePagination=function(e,t={}){const o=n.inject(a,{}),{pagination:u,...l}=t,{currentKey:i,pageSizeKey:c,totalKey:s,totalPageKey:v}=w({currentKey:"current",pageSizeKey:"pageSize",totalKey:"total",totalPageKey:"totalPage"},r().pagination||{},o.pagination||{},u||{}),d=w({defaultParams:[{[i]:1,[c]:10}]},l),{data:m,params:p,run:h,...g}=K(e,d),y=e=>{const[n,...t]=p.value||[],a=[{...n,...e},...t];h(...a)},E=e=>{y({[i]:e})},A=e=>{y({[c]:e})},T=n.computed((()=>f(m.value,s,0))),x=n.computed({get:()=>{var e,n;return null!==(e=null===(n=p.value)||void 0===n?void 0:n[0][i])&&void 0!==e?e:d.defaultParams[0][i]},set:e=>{E(e)}}),b=n.computed({get:()=>{var e,n;return null!==(e=null===(n=p.value)||void 0===n?void 0:n[0][c])&&void 0!==e?e:d.defaultParams[0][c]},set:e=>{A(e)}}),S=n.computed((()=>f(m.value,v,Math.ceil(T.value/b.value))));return{data:m,params:p,current:x,pageSize:b,total:T,totalPage:S,run:h,changeCurrent:E,changePageSize:A,changePagination:(e,n)=>{y({[i]:e,[c]:n})},...g}},e.useRequest=K,e.useRequestProvider=e=>{n.provide(a,e)},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue-demi")):"function"==typeof define&&define.amd?define(["exports","vue-demi"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VueRequest=e.VueRequest||{},e.vueDemi)}(this,(function(e,t){"use strict";const n={},a=Symbol("GLOBAL_OPTIONS_PROVIDE_KEY"),r=()=>n,o=Object.prototype.toString,u=e=>"[object Object]"===(e=>o.call(e))(e),l=e=>null!==e&&"object"==typeof e,i=e=>e instanceof Function,c=e=>null==e,s="undefined"==typeof window,v=()=>{var e;return!(!s&&!c(null===(e=window.document)||void 0===e?void 0:e.visibilityState))||"visible"===window.document.visibilityState},d=()=>new Promise((()=>{})),f=(e,t,n)=>{const a=t.replace(/\[(\d+)\]/g,".$1").split(".");let r=e;for(const e of a)if(r=Object(r)[e],void 0===r)return n;return r};function m(e,t){const n=Object.assign({},e);for(const e of t)delete n[e];return n}const p=e=>t.isRef(e)?e.value:e,h=new Map;function g(e,t,n){let a,r,o,u,i,c,s=0,v=!1,d=!1,f=!0;const m=!t&&0!==t&&"function"==typeof window.requestAnimationFrame;if("function"!=typeof e)throw new TypeError("Expected a function");function p(t){const n=a,o=r;return a=r=void 0,s=t,u=e.apply(o,n),u}function h(e,t){return m?(window.cancelAnimationFrame(i),window.requestAnimationFrame(e)):setTimeout(e,t)}function g(e){const n=e-c;return void 0===c||n>=t||n<0||d&&e-s>=o}function y(){const e=Date.now();if(g(e))return w(e);i=h(y,function(e){const n=e-s,a=t-(e-c);return d?Math.min(a,o-n):a}(e))}function w(e){return i=void 0,f&&a?p(e):(a=r=void 0,u)}function E(...e){const n=Date.now(),o=g(n);if(a=e,r=this,c=n,o){if(void 0===i)return function(e){return s=e,i=h(y,t),v?p(e):u}(c);if(d)return i=h(y,t),p(c)}return void 0===i&&(i=h(y,t)),u}return t=+t||0,l(n)&&(v=!!n.leading,d="maxWait"in n,o=d?Math.max(+n.maxWait||0,t):o,f="trailing"in n?!!n.trailing:f),E.cancel=function(){void 0!==i&&function(e){if(m)return window.cancelAnimationFrame(e);clearTimeout(e)}(i),s=0,a=c=r=i=void 0},E.flush=function(){return void 0===i?u:w(Date.now())},E.pending=function(){return void 0!==i},E}function y(e,t){for(const a in t)void 0!==t[a]&&(l(t[a])&&l(e[a])&&a in e?(u(t[a])||(n=t[a],Array.isArray(n)))&&y(e[a],t[a]):e[a]=t[a]);var n}function w(e,...t){const n=Object.assign({},e);if(!t.length)return n;for(const e of t)y(n,e);return n}var E=(e,{debounceInterval:n,debounceOptions:a,manual:r})=>{const o=t.ref(!1),u=t.ref(),l=t.computed((()=>a)),i=t.computed((()=>p(n))),s=t.ref(e.context.runAsync);return r||(o.value=!0),t.watchEffect((t=>{c(i.value)||(u.value=g((e=>e()),i.value,l.value),e.context.runAsync=(...e)=>new Promise(((t,n)=>{o.value?(o.value=!1,s.value(...e).then(t).catch(n)):u.value((()=>{s.value(...e).then(t).catch(n)}))})),t((()=>{var t;null===(t=u.value)||void 0===t||t.cancel(),e.context.runAsync=s.value})))})),{onCancel(){var e;null===(e=u.value)||void 0===e||e.cancel()}}},A=(e,{errorRetryCount:n=0,errorRetryInterval:a=0})=>{const r=t.ref(),o=t.ref(0),u=t.computed((()=>p(n))),l=t.computed((()=>p(a)));let i=!1;const c=()=>{o.value=0},s=t.computed((()=>{if(l.value)return l.value;return 1e3*Math.floor(Math.random()*2**Math.min(o.value,9)+1)})),v=()=>{r.value&&r.value()};return{onBefore(){i||c(),i=!1,v()},onSuccess(){c()},onError(){r.value=(()=>{let t;const n=-1===u.value,a=o.value<u.value;return(n||a)&&(n||(o.value+=1),t=setTimeout((()=>{i=!0,e.context.refresh()}),s.value)),()=>t&&clearTimeout(t)})()},onCancel(){c(),v()}}},T=(e,{ready:n=t.ref(!0),manual:a,defaultParams:r=[]})=>(t.watch(n,(t=>{!a&&t&&e.context.run(...r)}),{flush:"sync"}),{onBefore(){if(!n.value)return e.loading.value=!1,{isBreak:!0}}}),x=(e,{refreshDeps:n=[],refreshDepsAction:a,manual:r})=>(null!=n&&n.length&&t.watch(n,(()=>{a?a():!r&&e.context.refresh()})),{}),S=(e,{throttleInterval:n,throttleOptions:a})=>{const r=t.ref(),o=t.computed((()=>p(n))),u=t.computed((()=>a)),i=t.ref(e.context.runAsync);return t.watchEffect((t=>{if(c(n))return{};r.value=function(e,t,n){let a=!0,r=!0;if("function"!=typeof e)throw new TypeError("Expected a function");return l(n)&&(a="leading"in n?!!n.leading:a,r="trailing"in n?!!n.trailing:r),g(e,t,{leading:a,trailing:r,maxWait:t})}((e=>e()),o.value,u.value),e.context.runAsync=(...e)=>new Promise(((t,n)=>{r.value((()=>{i.value(...e).then(t).catch(n)}))})),t((()=>{var t;null===(t=r.value)||void 0===t||t.cancel(),e.context.runAsync=i.value}))})),{onCancel(){var e;null===(e=r.value)||void 0===e||e.cancel()}}};const b=(e,n,a)=>{var r,o;const{initialData:u,onSuccess:c,onError:s,onBefore:v,onAfter:f}=n,m=t.ref(null!==(r=null==a?void 0:a.loading)&&void 0!==r&&r),p=t.shallowRef(null!==(o=null==a?void 0:a.data)&&void 0!==o?o:u),h=t.shallowRef(null==a?void 0:a.error),g=t.ref(null==a?void 0:a.params),y=t.ref([]),w=t.shallowRef("pending"),E={},A=(T={status:w,loading:m,data:p,error:h,params:g},x=[],e=>{Object.keys(e).forEach((t=>{T[t].value=e[t]})),x.forEach((e=>e(T)))});var T,x;const S=(e,...t)=>{if("onQuery"===e){const e=y.value.map((e=>e.onQuery)).filter(Boolean);return{servicePromise:(n=e,a=t[0],()=>{let e=a;for(let t=n.length;t-- >0;)e=n[t](e);return e()})()}}{const n=y.value.map((n=>{var a;return null===(a=n[e])||void 0===a?void 0:a.call(n,...t)}));return Object.assign({},...n)}var n,a},b=t.ref(0);return E.runAsync=async(...t)=>{A({loading:!0,params:t,status:"pending"}),b.value+=1;const n=b.value,{isBreak:a,breakResult:r=d()}=S("onBefore",t);if(a)return A({status:"settled"}),r;null==v||v(t);try{const a=()=>new Promise((t=>t(e(...g.value))));let{servicePromise:r}=S("onQuery",a);r||(r=a());const o=await r;return n!==b.value?d():(A({data:o,loading:!1,error:void 0,status:"settled"}),S("onSuccess",o,t),null==c||c(o,t),S("onAfter",t,o,void 0),null==f||f(t),o)}catch(e){if(n!==b.value)return d();throw A({loading:!1,error:e,status:"settled"}),S("onError",e,t),null==s||s(e,t),S("onAfter",t,void 0,e),null==f||f(t),e}},E.run=async(...e)=>{E.runAsync(...e).catch((e=>{s||console.error(e)}))},E.cancel=()=>{b.value+=1,A({loading:!1}),S("onCancel")},E.refresh=()=>{E.run(...g.value||[])},E.refreshAsync=()=>E.runAsync(...g.value||[]),E.mutate=e=>{const t=i(e)?e(p.value):e,n=l(t)?Object.assign({},t):t;A({data:n}),S("onMutate",n)},{status:w,loading:m,data:p,error:h,params:g,plugins:y,context:E}};function P(e,n={},o){const u=t.inject(a,{}),l={...r(),...u,...n},{manual:i=!1,defaultParams:c=[]}=l,s=b(e,l);if(s.plugins.value=o.map((e=>e(s,l))),!i){const e=s.params.value||c;s.context.run(...e)}return t.onUnmounted((()=>{s.context.cancel()})),{loading:s.loading,data:s.data,error:s.error,params:s.params,cancel:s.context.cancel,refresh:s.context.refresh,refreshAsync:s.context.refreshAsync,mutate:s.context.mutate,run:s.context.run,runAsync:s.context.runAsync}}const O=new Map,R=new Map;var M=(e,{cacheKey:n,cacheTime:a=6e5,staleTime:r=0,getCache:o,setCache:u})=>{if(!n)return{};const l=i(n)?n:()=>n,s=t.ref((()=>{}));let v;const d=e=>o?o(e):(e=>{if(c(e))return;return h.get(e)})(e),f=(e,t,n)=>{u?u(e,n):((e,t,n)=>{const a=h.get(e);null!=a&&a.timer&&clearTimeout(a.timer);const r=setTimeout((()=>h.delete(e)),t);h.set(e,{...n,timer:r})})(e,t,n),((e,t)=>{R.has(e)&&R.get(e).forEach((e=>e(t)))})(e,n.data)},m=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),p=t=>{const n=l(t);return a=n,r=t=>{e.data.value=t},R.has(a)?R.get(a).push(r):R.set(a,[r]),()=>{const e=R.get(a).indexOf(r);R.get(a).splice(e,1)};var a,r},g=l(),y=d(g);return y&&m(y,"data")&&(e.data.value=y.data,e.params.value=y.params),g&&(s.value=p()),t.onUnmounted((()=>{s.value()})),{onBefore(t){const n=l(t),a=d(n);return a&&m(a,"data")?(o=a.time,-1===r||o+r>(new Date).getTime()?(e.data.value=a.data,e.loading.value=!1,{isBreak:!0,breakResult:a.data}):void(e.data.value=a.data)):{};var o},onQuery(t){const n=e.params.value,a=l(n);let r=(e=>O.get(e))(a);return r&&r!==v||(r=t(),v=r,((e,t)=>{O.set(e,t),t.then((t=>(O.delete(e),t))).catch((()=>{O.delete(e)}))})(a,r)),()=>r},onSuccess(e,t){const n=l(t);n&&(s.value(),f(n,a,{data:e,params:t,time:(new Date).getTime()}),s.value=p(t))},onMutate(t){const n=l(e.params.value);n&&(s.value(),f(n,a,{data:t,params:e.params.value,time:(new Date).getTime()}),s.value=p(e.params.value))}}};function j(){return(new Date).getTime()}var I,L=(e,{loadingDelay:n=0,loadingKeep:a=0})=>{const r=t.ref((()=>{})),o=t.computed((()=>p(n))),u=t.computed((()=>p(a)));let l=j(),i={};return{onBefore(){e.loading.value=!o.value,r.value(),r.value=(()=>{let t;return o.value&&(t=setTimeout((()=>{"pending"===e.status.value&&(e.loading.value=!0)}),o.value)),()=>t&&clearTimeout(t)})(),l=j()},onQuery(e){if(!u.value)return()=>e();i=function(e){let t,n;return new class extends Promise{constructor(e){super(e),this.cancel=()=>{n(),clearTimeout(t)}}}((a=>{n=a,t=setTimeout(n,e)}))}(u.value+o.value);const t=Promise.allSettled([e().finally((()=>{j()-l<=o.value&&i.cancel()})),i]).then((e=>{const t=e[0];return"fulfilled"===t.status?t.value:Promise.reject(t.reason)}));return()=>t},onCancel(){r.value()},onAfter(){r.value()}}};const C=new Set,B=new Set,D=new Set,N=(e,t)=>{let n;switch(e){case"FOCUS_LISTENER":n=C;break;case"RECONNECT_LISTENER":n=D;break;case"VISIBLE_LISTENER":n=B}if(!n.has(t))return n.add(t),()=>{n.delete(t)}},_=e=>{e.forEach((e=>{e()}))};!s&&null!==(I=window)&&void 0!==I&&I.addEventListener&&(window.addEventListener("visibilitychange",(()=>{v()&&_(B)}),!1),window.addEventListener("focus",(()=>_(C)),!1),window.addEventListener("online",(()=>_(D)),!1));var K=(e,{pollingInterval:n,pollingWhenHidden:a=!1,pollingWhenOffline:r=!1,errorRetryCount:o=0})=>{const u=t.ref(),l=t.ref(!1),i=t.computed((()=>p(n))),d=t.computed((()=>p(o))),f=[],m=e=>{e&&f.push(e)},h=()=>{return(a||v())&&(r||null===(e=!s&&(null===(t=window.navigator)||void 0===t?void 0:t.onLine))||void 0===e||e);var e,t},g=t=>{if(e.error.value&&0!==d.value)return;let n;if(!c(i.value)&&i.value>=0){if(!h())return void(l.value=!0);n=setTimeout(t,i.value)}return()=>n&&clearTimeout(n)},y=()=>{l.value&&h()&&(e.context.refresh(),l.value=!1)};return t.watch(i,(()=>{u.value&&(u.value(),u.value=g((()=>e.context.refresh())))})),a||m(N("VISIBLE_LISTENER",y)),r||m(N("RECONNECT_LISTENER",y)),t.onUnmounted((()=>{f.forEach((e=>e()))})),{onBefore(){var e;null===(e=u.value)||void 0===e||e.call(u)},onCancel(){var e;null===(e=u.value)||void 0===e||e.call(u)},onAfter(){u.value=g((()=>e.context.refresh()))}}};var k=(e,{refreshOnWindowFocus:n=!1,refocusTimespan:a=5e3})=>{const r=t.computed((()=>p(n))),o=t.computed((()=>p(a))),u=[],l=e=>{e&&u.push(e)},i=()=>{u.forEach((e=>e()))};return t.watchEffect((()=>{if(i(),r.value){const t=((e,t)=>{let n=!1;return(...a)=>{n||(n=!0,e(...a),setTimeout((()=>{n=!1}),t))}})(e.context.refresh,o.value);l(N("VISIBLE_LISTENER",t)),l(N("FOCUS_LISTENER",t))}})),t.onUnmounted((()=>{i()})),{}};function q(e,t){return P(e,t,[L,A,E,K,S,k,x,T,M])}e.clearCache=e=>{if(e){var t;const n=null===(t=h.get(e))||void 0===t?void 0:t.timer;n&&clearTimeout(n),h.delete(e)}else h.forEach((e=>e.timer&&clearTimeout(e.timer))),h.clear()},e.setGlobalOptions=e=>{Object.keys(e).forEach((t=>{n[t]=e[t]}))},e.useLoadMore=function(e,n){const{isNoMore:a,...r}=null!=n?n:{},o=t.shallowRef(),u=t.computed((()=>{var e;return(null===(e=o.value)||void 0===e?void 0:e.list)||[]})),c=t.ref(!1),s=t.ref(!1),v=t.ref(0),{runAsync:d,run:f,cancel:p,...h}=P((async t=>{const n=v.value,a=await e(t);return n===v.value&&(o.value=t?{...a,list:[...t.list,...a.list]}:a),a}),{...r,defaultParams:[],refreshDepsAction:()=>{null!=r&&r.refreshDepsAction?r.refreshDepsAction():w()},onError:e=>{var t;null==r||null===(t=r.onError)||void 0===t||t.call(r,e)},onSuccess:e=>{var t;null==r||null===(t=r.onSuccess)||void 0===t||t.call(r,e)},onBefore:()=>{var e;v.value+=1,s.value&&(s.value=!1,c.value=!0),null==r||null===(e=r.onBefore)||void 0===e||e.call(r)},onAfter:()=>{var e;c.value=!1,s.value=!1,null==r||null===(e=r.onAfter)||void 0===e||e.call(r)}},[A,E,S,x,T]),g=t.computed((()=>!(!a||!i(a))&&a(o.value))),y=()=>g.value?Promise.reject(((e,t=!1)=>{const n=`Warning: [vue-request] ${e}`;if(t)return new Error(n);console.error(n)})("No more data. You need to ignore this error by checking if `noMore` is false before calling `loadMoreAsync`",!0)):(s.value=!0,d(o.value)),w=()=>f();return{data:o,dataList:u,loadingMore:c,noMore:g,cancel:()=>{v.value+=1,p(),c.value=!1},mutate:e=>{const t=i(e)?e(o.value):e,n=l(t)?Object.assign({},t):t;o.value=n},refresh:w,refreshAsync:()=>d(),loadMore:()=>{y().catch((()=>{}))},loadMoreAsync:y,...m(h,["refresh","refreshAsync","mutate","params","data"])}},e.usePagination=function(e,n={}){const o=t.inject(a,{}),{pagination:u,...l}=n,{currentKey:i,pageSizeKey:c,totalKey:s,totalPageKey:v}=w({currentKey:"current",pageSizeKey:"pageSize",totalKey:"total",totalPageKey:"totalPage"},r().pagination||{},o.pagination||{},u||{}),d=w({defaultParams:[{[i]:1,[c]:10}]},l),{data:m,params:p,run:h,...g}=q(e,d),y=e=>{const[t,...n]=p.value||[],a=[{...t,...e},...n];h(...a)},E=e=>{y({[i]:e})},A=e=>{y({[c]:e})},T=t.computed((()=>f(m.value,s,0))),x=t.computed({get:()=>{var e,t;return null!==(e=null===(t=p.value)||void 0===t?void 0:t[0][i])&&void 0!==e?e:d.defaultParams[0][i]},set:e=>{E(e)}}),S=t.computed({get:()=>{var e,t;return null!==(e=null===(t=p.value)||void 0===t?void 0:t[0][c])&&void 0!==e?e:d.defaultParams[0][c]},set:e=>{A(e)}}),b=t.computed((()=>f(m.value,v,Math.ceil(T.value/S.value))));return{data:m,params:p,current:x,pageSize:S,total:T,totalPage:b,run:h,changeCurrent:E,changePageSize:A,changePagination:(e,t)=>{y({[i]:e,[c]:t})},...g}},e.useRequest=q,e.useRequestProvider=e=>{t.provide(a,e)},Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "vue-request",
"version": "2.0.0-rc.1",
"version": "2.0.0-rc.2",
"description": "Vue composition API for data fetching, supports SWR, polling, error retry, cache request, pagination and other cool features.",

@@ -64,2 +64,3 @@ "keywords": [

"@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.5",
"@babel/plugin-syntax-class-properties": "^7.12.13",
"@babel/plugin-transform-runtime": "^7.12.1",

@@ -66,0 +67,0 @@ "@babel/preset-env": "^7.12.1",

@@ -43,3 +43,3 @@ [English](./README.md) | 简体中文

目前处于 Beta 版本,详情请查看[更新日志](https://github.com/AttoJS/vue-request/issues/121)。
目前处于 RC 版本,详情请查看[更新日志](https://github.com/AttoJS/vue-request/issues/121)。

@@ -69,4 +69,4 @@ ## 为什么选择 VueRequest

- [English](https://www.attojs.org/)
- [中文文档](https://www.attojs.com/)
- [English](https://next.attojs.org/)
- [中文文档](https://next.attojs.com/)

@@ -83,2 +83,4 @@ ## 安装

yarn add vue-request@next
# or
pnpm install vue-request@next
```

@@ -91,3 +93,3 @@

```html
<script src="https://unpkg.com/vue-request/dist/vue-request.min.js"></script>
<script src="https://unpkg.com/vue-request@next/dist/vue-request.min.js"></script>
```

@@ -124,3 +126,3 @@

在这个例子中,`useRequest` 接收了一个 `service` 函数。`service`是一个异步的请求函数,换句话说,你可以使用 **axios** 来获取数据,然后返回一个 **Promise**。更具体的说明可以在[文档](https://www.attojs.com/guide/documentation/dataFetching.html)中查看。
在这个例子中,`useRequest` 接收了一个 `service` 函数。`service`是一个异步的请求函数,换句话说,你可以使用 **axios** 来获取数据,然后返回一个 **Promise**。更具体的说明可以在[文档](https://next.attojs.com/guide/documentation/dataFetching.html)中查看。

@@ -135,3 +137,3 @@ `useRequest` 还返回了三个值, `data`、`loading` 和 `error`。当请求还没完成时, `data` 将会为 `undefined` 同时,`loading` 将被设置为 `true`。当请求完成后,则将会根据请求结果来设定 `data` 和 `error`,并对页面进行渲染。这是因为 `data`、 `loading` 和 `error` 是 Vue 的 [响应式引用(Refs)](https://v3.cn.vuejs.org/guide/reactivity-fundamentals.html),它们的值将根据请求状态及请求结果来修改。

有些时候,你要确保多个浏览器窗口之间数据的一致性;又或者是当用户电脑在休眠状态重新激活后,页面的数据需要同步到最新状态时。`refreshOnWindowFocus` 可能会为你节省很多逻辑代码。[点击这里直达文档](https://www.attojs.com/guide/documentation/refreshOnWindowFocus.html)
有些时候,你要确保多个浏览器窗口之间数据的一致性;又或者是当用户电脑在休眠状态重新激活后,页面的数据需要同步到最新状态时。`refreshOnWindowFocus` 可能会为你节省很多逻辑代码。[点击这里直达文档](https://next.attojs.com/guide/documentation/refreshOnWindowFocus.html)

@@ -149,3 +151,3 @@ ```ts

有些时候,你要确保多个设备间数据的同步更新。这时候可以用我们提供的 `pollingInterval` 来定期重新请求接口,这样就可以保证多设备间的数据一致性。当用户进行修改数据时,两个窗口将会实时同步更新。[点击这里直达文档](https://www.attojs.com/guide/documentation/polling.htm)
有些时候,你要确保多个设备间数据的同步更新。这时候可以用我们提供的 `pollingInterval` 来定期重新请求接口,这样就可以保证多设备间的数据一致性。当用户进行修改数据时,两个窗口将会实时同步更新。[点击这里直达文档](https://next.attojs.com/guide/documentation/polling.html)

@@ -152,0 +154,0 @@ ```ts

English | [简体中文](README-zh_CN.md)
<p align="center">
<a href="https://www.attojs.org">
<a href="https://next.attojs.org">
<img

@@ -43,3 +43,3 @@ width="150"

Currently in Beta version. For details, please see the [changelog](https://github.com/AttoJS/vue-request/issues/121).
Currently in RC version. For details, please see the [changelog](https://github.com/AttoJS/vue-request/issues/121).

@@ -68,4 +68,4 @@ ## Why VueRequest

- [English](https://www.attojs.org/)
- [中文文档](https://www.attojs.com/)
- [English](https://next.attojs.org/)
- [中文文档](https://next.attojs.com/)

@@ -82,2 +82,4 @@ ## Install

yarn add vue-request@next
# or
pnpm install vue-request@next
```

@@ -90,3 +92,3 @@

```html
<script src="https://unpkg.com/vue-request/dist/vue-request.min.js"></script>
<script src="https://unpkg.com/vue-request@next/dist/vue-request.min.js"></script>
```

@@ -123,3 +125,3 @@

In this example, `useRequest` accepts a `service` function. `service` is a asynchronous function. In other words, you can use **axios** to fetch data and return a **Promise**. More specific instructions can be viewed in [document](https://www.attojs.org/guide/documentation/dataFetching.html).
In this example, `useRequest` accepts a `service` function. `service` is a asynchronous function. In other words, you can use **axios** to fetch data and return a **Promise**. More specific instructions can be viewed in [document](https://next.attojs.org/guide/documentation/dataFetching.html).

@@ -134,3 +136,3 @@ `useRequest` also return 3 values: `data`, `loading` and `error`. When the request is not yet finished, data will be `undefined` and `loading` will be `true`. And when we get a response, it sets data and error based on the result of service and rerenders the component. This is because `data` and `error` are [Reactivity(Refs)](https://v3.vuejs.org/guide/reactivity-fundamentals.html), and their values will be set by the service response.

Sometimes, you need to ensure data consistency between multiple browser windows; or when the user's computer is reactivated in the dormant state, the page data needs to be synchronized to the latest state. `refreshOnWindowFocus` may save you a lot of code. [Click here to go to the document](https://www.attojs.org/guide/documentation/refreshOnWindowFocus.html)
Sometimes, you need to ensure data consistency between multiple browser windows; or when the user's computer is reactivated in the dormant state, the page data needs to be synchronized to the latest state. `refreshOnWindowFocus` may save you a lot of code. [Click here to go to the document](https://next.attojs.org/guide/documentation/refreshOnWindowFocus.html)

@@ -148,3 +150,3 @@ ```ts

Sometimes, you want to ensure that data is synchronized and updated between multiple devices. At this time, we can use the `pollingInterval` provided by us to periodically re-request the request API, so that the data consistency between multiple devices can be guaranteed. When the user modifies the data, the two windows will be updated simultaneously in real time. [Click here to go to the document](https://www.attojs.org/guide/documentation/polling.htm)
Sometimes, you want to ensure that data is synchronized and updated between multiple devices. At this time, we can use the `pollingInterval` provided by us to periodically re-request the request API, so that the data consistency between multiple devices can be guaranteed. When the user modifies the data, the two windows will be updated simultaneously in real time. [Click here to go to the document](https://next.attojs.org/guide/documentation/polling.html)

@@ -151,0 +153,0 @@ ```ts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc