Given the following Vue method to call an API using Axios to fetch some data:
fetch: function() {
console.log('Commence call to API!');
axios.get("fetch.php")
.then(response => {
if (response.status === 204) {
this.noContent = true;
} else {
console.log(response.data);
}
});
console.log('Method complete!');
},
The expected in the console output should be as follows:
- Commence call to API!
- {{Some response data}}
- Method complete!
Instead, what often happens is the following:
- Commence call to API!
- Method complete!
- {{Some response data}}
How can I ensure that the method behaves in a 'sequential' manner?