I can’t get a data property to not be null when I’m using axios, I don’t know whether it is because the request takes time and the value is set before it is run, I just don’t know
The property in question is responseBaseCalendarShifts
data() {
return {
dateList: [],
year: new Date().getFullYear(),
monthNumbers: Array.from(Array(12).keys()),
lastDateClicked: null,
responseBaseCalendarShifts: []
}
},
getDates() {
let dateArray = [];
let currentDate = new Date(this.year, 0, 1);
this.getBaseCalendarShifts();
let baseCalendarShifts = this.responseBaseCalendarShifts;
console.log(this.responseBaseCalendarShifts) // here the value is null
while (currentDate <= new Date(this.year, 11, 31)) {
let dateProperties = {
id: currentDate.getFullYear() + "-" + currentDate.getMonth() + "-" + currentDate.getDate(),
date: currentDate,
year: currentDate.getFullYear(),
month: currentDate.getMonth(),
day: currentDate.getDate(),
dayOfWeek: currentDate.getDay(),
active: false
};
dateArray.push(dateProperties);
currentDate = currentDate.addDays(1);
}
this.dateList = dateArray;
},
getBaseCalendarShifts() {
axios.post(this.route, null, {
params: {
year: this.year
}
})
.then(response => {
this.responseBaseCalendarShifts = response.data;
console.log(response.data); // here the value is correct
})
.catch(function (error) {
flash('error', error);
})
}
},
Please help