I am facing an issue with two versions of code, where the second version is not functioning as expected. I suspect it may be due to a contextual problem that I am unable to pinpoint.
The first version of the code works fine:
// 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 the second version, I am unable to retrieve the response data in the 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)
})
},
I cannot understand why I am unable to access the content of the response within the sendDatas function, considering the async callApi function returns a promise.
Your assistance in resolving this issue would be greatly appreciated :)