Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Accessing to localhost with AXIOS in Vue project

How could I get access to my JSON file locally with the Vue project?

I can use it with some external link (and it works):

mounted() {
    this.loading = true;
    axios.get("https://jsonplaceholder.typicode.com/todos").then((res) => {
      this.posts = res.data;
      this.loading = false;
      this.sliceIt();
});

But I would like to put this file (todos.json) temporarily to src/assets/todos.json and use it from there.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But this:
axios.get("http://localhost/assets/todos.json").then((res) => {
doesn’t work.

>Solution :

You can’t get data from custom folder with axios. You should use a static folder to save todos.json file. So you should change axios call to like this:

axios.get("/static/todos.json")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading