[Vuejs]-Vue infinite loop … in method

0👍

Ok it seems impossible to avoid this problem. So I changed my approach. I didn’t update the date while populating the doom, instead, I used vuex store and getters. When returning from getters, I changed the values there and once all date changes are done, I simply returned the array. It worked nicely. Here is my code

This code is a bit changed in terms of logic as I added dynamic conditions. But concept is same.

fixture(state){
  // we can actually update here

  for(var i in state.fixture){

      var details=state.fixture[i].row
      for(var j in details){   
          //console.log(details[j].date.startingDate)

          if(state.counter==state.groupCount){  

              // increase the date 
             if(state.date){
              var currDate = new Date(state.date) 
            }else{
              var currDate = new Date(details[j].date.startingDate) 
            }

              var d=currDate.setDate(currDate.getDate() + 7);  
              var d=new Date(d)
              var newDate=d.toISOString()
              var dateArr=newDate.split("T")
              var res=dateArr[0]
              details[j].date.startingDate=res 

              state.date=details[j].date.startingDate   

              state.counter=1

          }else{

            if(state.date){ 
              details[j].date.startingDate=state.date 
            }

            state.counter++ 
          }

      }
      state.counter=0
      state.date=''
  }

  return state.fixture
},

Hope this approach helps others.

Leave a comment