@khaledosman/vue3-axios v1.1.3
vue3-axios
Composition API & Vue component helpers for making API requests and rendering the results in vue 3
Guide
The library offers 3 different layers of abstraction for making API requests that can be used separately:
useAPIis a hook that can be used in any component and gives the user full control of the request (cancellation, caching, refetch, error & loading states)AxiosComponentis an Async component that uses theuseAPIhook to render/mount itself only when the initial request is done and the results are ready. it delegates rendering of error / loading or results via named slots.VueAxiosComponentWhich usesAxiosComponentto provide generic error & loading states and uses the newSuspenseAPI to handle rendering of the Async Component. it delegates rendering of results via a named slot.
the useAPI hook uses cachedGet function for get requests which provides two different strategies: Online first, and offline first:
In Online first mode the request goes first to the network then saves the results in cache, or fallbacks to the cache if the user is offline or the network request fails, this is best-suited for content that needs to be always fresh.
In Offline first mode the results are returned from the cache first, then a network request is done in the background to update the cache for next use or go to the network if there're no results in cache. This is best suited for apps that need to work under any network condition like bad Wifi / Slow internet or even completely offline with the compromise of less fresh data (i.e twitter, facebook, instagram). It also offers the best performance since the user can see results instantly without even the need for a loading state.
Example
HelloWorldComponentis a use case example, which show cases howVueAxiosComponentcan be usedVueAxiosComponentis an example, which show cases howAxiosComponentcan be usedAxiosComponentis an example which show cases howuseAPIhook can be used