Home

Issue: 123

What is the best way to load json.

[issue link]

I have a json file with data to initialise my pages. I put it in /static folder e.g. /static/data.json. Then I use axios.get() to load it from /data.json. That works on the client, but fails on the server.

I have these questions, which I think will be very useful for wider audience as well:

  1. What is wrong with the example below?
  2. Is /static the best place to put data files?
  3. is loading them via axios the best way ?
  4. What if I want to load from 3 different locations for server, for client and for static build?
 export default {
    data({ req, params, store }) {
      
      return axios.get('/data.json')
        .then((res) => {
          return {
            authors: res.data
          }
        })
    }
  }

Thanks in advance

This question is available on Nuxt.js community (#c100)