Skip to content
Advertisement

Browser shows get request is made but nothing is returned in promise?

Currently stumped on an issue and not finding anything online to help me out. I am making a very basic HTTP get request to get a JSON object from an API I made (express+CORS enabled).

I’ve tried with both Axios and VueResource but having the same issue where my browser shows that the request is made and is successful (even shows the expected data).

Shows that http GET request is OK

But I never get any returns in the promise. And using both console.logs and breakpoints it shows the .then and .catch functions are never run.

  methods: {
    getTasks() {
      return this.$http.get("http://localhost:3080/api/tasks").then(response => function() {
        console.log("in"); // This console.log is never run
        this.data = response.data; // this.data is still null
      }).catch(err => {
        // No errors are returned
        console.log(err);
      });
    }
  },
  mounted() {
    this.getTasks();
  }

Advertisement

Answer

The correct syntax for arrow functions is:

 (params) => {
  // code
 }

Change your then callback to:

 getTasks() {
      return this.$http.get("http://localhost:3080/api/tasks").then(response => {
        console.log("in"); // This console.log is never run
        this.data = response.data; // this.data is still null
      }).catch(err => {
        // No errors are returned
        console.log(err);
      });
    } 
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement