0

I am writing a Vue app that displays certain data from json. Getting json from an external API with axios works as expected. The problem is that I also want to be able to use data that is on my computer.

At first I tried sending it in form data. This works but the problem is that max url parameter length is limited. I cannot use a post request because the app says: "Cannot POST /"

Is it possible to show data from a local file on vue app running on a server?

EDIT: Let's say the json is "{ "id": 1, "name": "foo" }". I can send it to my app with

  var json = '{ "id": 1, "name": "foo" }';
  var form = $('<form action="' + url + '" method="get">' +
    '<input type="hidden" name="json" value="' + encodeURI(json) + '" />' +
    '</form>');
  $('body').append(form);
  form.submit();

which can then display this data. The issue is that 2048 characters is not enough for my use case.

Dan
  • 59,490
  • 13
  • 101
  • 110
Heix
  • 1
  • 3
  • can you show me a type of the data you are trying to load – Quantumass Apr 09 '20 at 12:50
  • Questions seeking debugging help ("**why isn't this code working?**") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it **in the question itself**. Questions without a **clear problem statement** are not useful to other readers. See: [How to create a Minimal, Reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Phoenix1355 Apr 09 '20 at 12:50

1 Answers1

0

Load dynamic files

You can't read a dynamic local file using a front end framework (since the file won't exist if the code runs on another computer)

The best way to do it, is to serve your file from a server using PHP or NodeJs

Static files

But if the file you are trying to load is static and you won't be changing it periodically you can put it in the asset and load it using require

Quantumass
  • 826
  • 6
  • 11