Необходимо, чтобы числа каждого месяца отображались в соответствии с днями недели.
const date = reactive({
currentDate: new Date(),
});
const currentYear = ref(date.currentDate.getFullYear());
const currentMonth = ref(date.currentDate.getMonth());
const currentDay = ref(date.currentDate.getDate());
const lastDayMonth = computed(
() => new Date(currentYear.value, currentMonth.value + 1, 0).getDate(),
);
const firstDayMonth = computed(
() => new Date(currentYear.value, currentMonth.value, 1).getDate(),
);
const getCalendar = computed(() => {
const currMonthDays = [];
const preMonthDays = [];
for (let i = 1; i <= lastDayMonth.value; i += 1) {
currMonthDays.push(i);
}
for (let i = firstDayMonth.value; i > 0; i -= 1) {
preMonthDays.push('');
}
const resDays = [...preMonthDays, ...currMonthDays];
return resDays;
});
Есть проблема именно с этим циклом:
for (let i = firstDayMonth.value; i > 0; i -= 1) {
preMonthDays.push('');
}
Но в чём именно ошибка, не могу понять.