0

I'm want write a simple one page application that utilizes JSON data stored on a local hard drive. I will use VueJS V3 for data binding to the HTML page.

The HTML page will be a data entry form that when the user presses the save button, the local JSON data will be updated.

That said, I have no clue within VueJS of how to read/write to a local JSON fie.

Anyone have a simple example to share with me?

Thanks in advance or any help.

Harvey Mushman
  • 615
  • 1
  • 11
  • 23
  • You can't directly access files on the local hard drive from the browser. – derpirscher Jul 10 '21 at 20:18
  • Assuming a browser within the last several years is being used, the following allows the browser to write to the local hard drive. window.webkitURL.createObjectURL(textToBLOB); – Harvey Mushman Jul 10 '21 at 22:09
  • Here is a link to an article that shows a demo working... https://www.encodedna.com/javascript/how-to-save-form-data-in-a-text-file-using-javascript.htm – Harvey Mushman Jul 10 '21 at 22:17
  • That's why I wrote "directly". The article you linked, opens a download dialog ... – derpirscher Jul 11 '21 at 06:57
  • Interesting, I tried the published code is a test page and it ran without opening a dialog but for my application a dialog would not be a bad thing. But my present problem is teaching VueJS to read the local saved JSON into a data object. Any suggestions where I might be able to find that example? – Harvey Mushman Jul 11 '21 at 12:47
  • Did you configure your browser for a default download location? For reading a file via an `` element you can refer to this question https://stackoverflow.com/questions/750032/reading-file-contents-on-the-client-side-in-javascript-in-various-browsers – derpirscher Jul 11 '21 at 13:42

0 Answers0