Home > database >  Accessing to localhost with AXIOS in Vue project
Accessing to localhost with AXIOS in Vue project

Time:12-07

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.

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

CodePudding user response:

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")
  • Related