Jim Hu
Jim Hu

Reputation: 11

Why in Nuxt.js official document they use both fetch and axios in fetch function

  1. Why in the official document do they use both fetch and axios in fetch function?

Just because it needs to return a Promise?

  1. can we use fetch API in asyncData function? Does it make sense?

fetch example in official document

Upvotes: 1

Views: 1515

Answers (2)

Jim Hu
Jim Hu

Reputation: 11

what I know the process is

  1. get ( fetch ) the data with axios or node-fetch with node platform to the server ( hold data on the server )
  2. build the first page for the client and pre-render from server
  3. then client save the data, and SPA works.

so we can't use fetch because fetch methods is the native way only on the browser. Correct me if I'm wrong. Thanks.

Upvotes: 0

Aldarund
Aldarund

Reputation: 17621

There no use of fetch in docs that you linked. There only fetch function that defined for nuxt itself.

You can use http fetch instead of axios, but it wont work on node. You will need to use polyfill for node like node-fetch

Basically you can use any library you want to get your data. Axios just used as a most common library that is used for that purpose. There nothing specific to axios in nuxt itself

Upvotes: 3

Related Questions