[Vuejs]-Cannot return the value from a function in AJAX

0👍

You’re dealing with Promises in this case. They do not behave like a typical function in JavaScript. I would recommend starting with some basics:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

As to your question, getData does not return anything, nor is there a getTaskData in the code you’ve provided.

0👍

As said in the previews response you’re dealing with promise,
You need to wait finishing you’re Ajax request and then you deal with response,
In your code you can do like this

async function getData() {
  const response = await axios.get('/task')
  return response
}

Call function with callback for the success and failure cases of the Promise

getData()
  .then(response => {
    console.log(response.data.tasks)
  })
  .catch(error => {
    console.log("ERROR")
  }) 

Leave a comment