DenisMasot
DenisMasot

Reputation: 747

Where is the loop infinity?

I find myself with an infinite loop error but I don’t see where it is. That’s when I add class.

template :

  <tr class="listOfDay">
    <td>Jour de la semaine</td>
    <td v-for="day in nbDaysInMonth" :key="index" :class="{weekend: isWeekend}">{{dayOfWeek(day,index)}}</td>
  </tr>

script :

data: () {
   isWeekend: false,
},
methods : {
  dayOfWeek(day) {
    var d = moment(new Date(this.currentYear + '-' + this.nbMonth + '-' + day)).day();
    if(d === 5 || d === 6) {
      this.isWeekend = true
    } else {
      this.isWeekend = false
    }
    return this.days[d]
  }
}

Upvotes: 0

Views: 102

Answers (1)

Michael Pratt
Michael Pratt

Reputation: 3496

You're changing isWeekend as the component is rendered, therefore causing the component to rerender, I believe this is causing the infinite loop.

Don't calculate isWeekend as part of dayOfWeek. I think the best solution would be to create another method.

EDIT: as suggested in a comment, using computed values is probably an even better solution.

Upvotes: 4

Related Questions