Home > OS >  Nuxt.js SSG (Static site generator) fetch API data
Nuxt.js SSG (Static site generator) fetch API data

Time:08-22

When building a project with the static site generator, I understand that the document created in advance is provided to the user.

If there is a logic that fetches data using axios, etc. and displays it on the screen when entering the page, does the corresponding API get cached or not called?

CodePudding user response:

You have 2 lifecycle hooks that you can use to fetch data: fetch and asyncData as shown here: https://nuxtjs.org/docs/features/data-fetching

Depending on how you organize your project and what you need, there will be content generated in advanced thanks to SSG and some of it can also be run on the client, like if you need some auth'ed content.

CodePudding user response:

It seems that you use full static mode. In this mode, Nuxt does not call asyncData and fetch because all data must be loaded in the generation step. https://nuxtjs.org/announcements/going-full-static/#current-issues You can remove target: 'static' from your nuxt.config.js and call nuxt generate. You get generated static but asyncDataandfetch` must be available.

  • Related