I have created a basic Vue calendar where the days of the month are shown using a v-for loop that generates an array of $refs. Each date element has a unique ID assigned to it. The issue I am facing is that when I try to highlight a particular day by clicking on it, the same day in every other month also gets highlighted. For example, if I click on May 25th, the 25th of every other month ends up being highlighted as well, even though I am toggling the class based on the specific element's ID.
Is there a way to only highlight the selected day without affecting others?
Below is the code snippet for the highlight method:
highlightDay(index) {
let selected = this.$refs.day[index].id;
if (!this.$refs.day[index].classList.contains("today")) {
this.$refs.day.forEach(el => {
if (el.classList.contains("selected-day")) {
el.classList.toggle("selected-day");
}
});
document
.getElementById(selected)
.classList.toggle("selected-day");
}
}
For reference, here is a link to the full project: https://codepen.io/reticent67/pen/EzWomG