I have two different version of code but I am having trouble understanding why the second version is not working correctly. I think this is a "context" problem, but I don't understand.
In this version I get the response
// Fist version (it works)
methods: {
async sendDatas() {
await this.$axios({
method: 'post',
url: '/url',
data: {
email: this.email,
},
})
.then((response) => {
console.log(response)
})
.catch((error) => {
console.log(error)
})
},
In this version i can't get the response data in callApi function
sendDatas() {
this.callApi(this.email)
.then((response) => {
// Here "response" is "undefined"
console.log(response)
})
.catch((error) => {
console.log(error)
})
},
async callApi(email) {
await this.$axios({
method: 'post',
url: '/url',
data: {
email,
},
})
.then((response) => {
// Here "response" is ok"
console.log(response)
})
.catch((error) => {
console.log(error)
})
},
The async callApi function returns a promise, why can't I get the content of the response in the sendDatas function?
Thanks for your help :)