nuxt.js logo

Using AsyncData for Server-Side Data Fetching


Nuxt.js provides a unique asyncData method that you can define in your page components to fetch data server-side and render it directly in the initial HTML. This is extremely useful for SEO and initial page load performance.


export default {
        async asyncData({ params, $axios }) {
          const data = await $axios.$get(`/api/posts/${params.id}`);
          return { post: data }
        }
      }