Then is not a function on axios async/await post request
The await
keywords awaits a promise (that means it internally handles the then
) but it does not return a promise. Instead await
returns the result of the promise.
Therefore, the correct way to do what you want is:
async sendUserData() { try { const response = await axios.post('/register', { email: this.register.email.trim(), password: this.register.password.trim(), }); console.log(response); } catch (e) { console.log(e); }}
However, the async
keyword returns a promise. So you should call your function like this:
sendUserData().then(console.log('done'));