0

I need to store my data in .txt or .json files.

And it's good to load file with axios, for example, and then output the JSON.parsed data. For example, I have file "data/tweets.json", and there are tons of tweets in json format. Well, I use axios.get ... and then I output content to needed component.

Well, and I cannot use things like import tweets from "@/data/tweets.ts", I need to make something db shaped, but without db engines.

Is there some traditional, easy way to make it?

Maybe there is some kind of node_nodule for the task?

Is there some config for Vue app for the case?

Alex Ax
  • 3
  • 2

1 Answers1

0

Make an HTTP request to get the static data from your server using Axios or fetch.

axios.get('/data/tweets.json').then((res) => {
  // bind your data in Vue
  this.tweets = JSON.parse(res.data)
})
daiyanze
  • 103
  • 7
  • Well, I know, how axios works, thanks. But, well, this example doesn't answer, how can I make something db shaped in a Vue project. Well, I use @vue/cli -- and then I have a list of scripts, that I can call from terminal like that: ```npm run build``` etc. Not imported files are not included into the build, well, and I need to add excluded files to the build. Is there some default way to leave not imported files in some folder of the build in the build results? – Alex Ax Nov 13 '19 at 06:59
  • I'm a bit obscure with the "db shaped" thing. But I think I understand that you perhaps want to include the file without explicitly importing it in your program. – daiyanze Nov 13 '19 at 07:18
  • So I think using Webpack loader or plugin may help you copy that file to the build folder. Check this out. https://github.com/webpack-contrib/copy-webpack-plugin & https://stackoverflow.com/questions/27639005/how-to-copy-static-files-to-build-directory-with-webpack – daiyanze Nov 13 '19 at 07:20