hook-fetch
Version:
A lightweight and modern HTTP request library developed based on the native Fetch API of the browser, providing a user-friendly interface similar to Axios and powerful extensibility.
2 lines • 988 B
JavaScript
import{ref as e}from"vue";function t({request:t,onError:n}){let r=null,i=e(!1),a={name:`__vue-hook__`,onFinally(){i.value=!1}},o=(...e)=>{if(r)return r;if(r=t(...e),!r||!(`__injectPlugins__`in r))throw Error(`Instance is not a HookFetchRequest`);return r?.__injectPlugins__([a]),r},s=(...e)=>{if(r=t(...e),!r||!(`__injectPlugins__`in r))throw Error(`Instance is not a HookFetchRequest`);return r?.__injectPlugins__([a]),i.value=!0,r?.catch(e=>{i.value=!1,e instanceof Error&&!e.message.includes(`Unexpected token`)&&e.name!==`AbortError`&&n?.(e)}),r},c=(...e)=>(s(...e),r.text()),l=(...e)=>(s(...e),r.stream()),u=(...e)=>(s(...e),r.blob()),d=(...e)=>(s(...e),r.arrayBuffer()),f=(...e)=>(s(...e),r.formData()),p=(...e)=>(s(...e),r.bytes()),m=()=>{if(i.value=!1,r)try{r?.abort()}catch(e){console.error(`cancel error`,e)}};return{request:o,stream:l,text:c,blob:u,arrayBufferData:d,formDataResult:f,bytesData:p,cancel:m,loading:i}}export{t as useHookFetch};
//# sourceMappingURL=index.mjs.map