Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between fetch and nuxtServerInit in Nuxt.js?

Tags:

nuxt.js

According to the Nuxt documentation these methods are used to pre-fill store before page is served.

In what cases should I use fetch and in what cases - nuxtServerInit?

like image 929
31415926 Avatar asked Dec 13 '22 13:12

31415926


1 Answers

I think of nuxtServerInit as the place to go if I need to make requests that prefetch options that are used in all the App, languages, configaration values, input options, etc...

fetch &asyncData instead fire both on the client and server once that pages gets rendered.

That means that fetch & asyncData will fire every time the component is matched by the router and nuxtServerInit only once, at the beginning, on the server, and never again.

like image 146
Borjante Avatar answered Jan 14 '23 14:01

Borjante