I'm having a little trouble setting one of my this.values
within my Vue
application. I believe I'm either not understanding async axios calls correctly, or how async works within axios
.
I have the following axios
post method within my Vue
application:
postRequest: async function(event) {
event.preventDefault();
let config = {
headers: {
"X-CSRFToken": this.csrfToken,
"Content-Type": 'application/x-www-form-urlencoded',
}
}
let formData = new FormData();
formData.append('data', someData);
await axios.post('{{ request_absolute_uri }}', formData, config).then(function(response) {
this.responseMessage = response.data.message;
}).catch(function(error) {
console.log(error);
});
}
console.log(this.responseMessage)
return this.responseMessage;
}
My response.data.message
is being passed back from my framework as True/true but it seems I'm not returning anything from the postRequest
function? The post definitely hits the server as logging shows everything I want - then returns back message = true
in json response context (using console.log(this.responseMessage)
directly before returning the same value. However, nothing on the template changes or updates from this....
I'm assuming at this point that I have missed something incredibly simple!