0

I have a JSON file in my Vue JS project, nested in the folder structure

src/assets/json/people.json

I'm trying to make an axios request to the json resource in my App.vue file

export default {
  name: "App",
  data: function() {
    return {
      people: []
    }
  },
  created: function() {
    this.fetchPeople();
  },
  methods: {
    fetchPeople: function() {
      let url = "./src/assets/json/people.json"
      axios.get(url)
      .then(res => {
       this.people = JSON.parse(res);
      })
    }
  }
};

On my console, I'm getting the error below:

Failed to load resource: the server responded with a status of 404 (Not Found)
Uncaught (in promise) Error: Request failed with status code 404
  at createError (createError.js?2d83:16)
  at settle (settle.js?467f:17)
  at XMLHttpRequest.handleLoad (xhr.js?b50d:59)

1 Answer 1

2

Why would you that?

import people from "./src/assets/json/people.json"

would probably do the work.

Axios is an HTTP agent to fetch data from a remote server. If the file is local, just import it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.