I am attempting to implement a feature where I can check the response object from the initial axios call, and if it is empty, proceed to the second call (otherwise, I will generate an error message).
Essentially, the second axios call should only be triggered if the userStatus object is empty. While both axios calls function independently, how can I ensure that the second call is made when the object is empty?
Currently, I receive a 200 response from the first axios call and an empty userStatus object in the console, but the second call does not occur.
changeStatus: function(event) {
let user = this.auth_user;
axios.get('/user/' + user + '/status')
.then((response) => {
this.userStatus = response.data
})
if(this.userStatus.length < 1){
let data = {
id: event.id,
status: 'A'
};
axios.post('/status/change',data)
.then((response) => {
if (response.data.success == false) {
this.errors = [];
const errorLog = Object.entries(response.data.errors);
for (var i = errorLog.length - 1; i >= 0; i--) {
console.log(errorLog[i][1][0]);
this.errors.push(errorLog[i][1][0]);
}
}
})
}else{
console.dir('No');
}
},