R
R
Roman2019-06-21 13:06:01
Vue.js
Roman, 2019-06-21 13:06:01

What is the best way to store content in a separate JSON file in Nuxt (SPA-mode)?

Hello.
I'm doing a pet-project on Nuxt. Now I want to organize the storage of data (content) in a json file (such as such a "flat" database).
What is the best way (Nuxt-Way) to load this data into the project for display.
So far, I just put them in a separate component in data() and import them together with the component))
Everything works, but I feel that there is something ugly in this))))))
What is the best way to do it?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Klein Maximus, 2019-07-02
@kleinmaximus

If this data is not planned to be changed, then you can leave it as it is.
But it's better to put the data files in the static folder so that you can download via http request using, for example, axios. Write the received response to the state of the component or store.
And it is even better to write an intermediate API for this matter.
Thus, it will be possible to make several abstractions that will help keep the code loosely coupled.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question