In this post we’ll look at how we can use Vue 3’s composition API to leverage the stale-while-revalidate technique in data fetching.
When building applications with frontend frameworks, one aspect that generates a lot of opinions is the concept of data fetching. In basic scenarios, you would handle your data using a combination of an HTTP client (e.g Axios) and Vue’s lifecycle methods.
More complex situations such as larger applications with multiple components, which in most cases will be routed, will require a different approach. Also, the sequence in which data is to be fetched — before or after certain components have been loaded — is also a concern. In this post, we’ll take a look at the best practices for fetching data in advanced scenarios when working with Vue. We’ll also learn how we can use Vue 3’s composition API to leverage the stale-while-revalidate
technique in data fetching.
Data fetching when various routed components are involved could get complex. In some cases, we may want to display some data while a particular route is being navigated. Vue Router handles this properly by providing options to either fetch the data before navigation is made or after. Let’s take a look at both scenarios.
#vue #javascript #web-development