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:
- What is wrong with the example below?
- Is
/staticthe best place to put data files? - is loading them via axios the best way ?
- 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