title: vue-star-rating TypeError: Cannot read property 'length' of undefined at listToStyles.js:26
body: <p>Getting this error while calling getRating function in Vue. I'm using the Vue-star-rating package in laravel. don't understand what is the problem.</p>
  
  <pre><code> getRating(){
                      var pathArray = location.pathname.split('/');
                      var pid = pathArray[2];
                      fetch(`/api/rating/${pid}`)
                      .then(res =&gt; res.json())
                      .then(res =&gt; {
                          var mydata = res.data;
                          this.totaluser = mydata.length;
                          var sum = 0;
                          for(var i=0; i &lt; mydata.length; i++){
                              sum += parseFloat(mydata[i]['rating']);
                          } 
                          var avg = sum/mydata.length;
                          this.totalrate = parseFloat(avg.toFixed(1));
                          var bar1 = 0;
                          var bar2 = 0;
                          var bar3 = 0;
                          var bar4 = 0;
                          var bar5 = 0;
                          for(var j = 0; j &lt; mydata.length; j++){
                              if(parseInt(mydata[j]['rating']) == '1'){
                                  bar1 += 1;
                              }
                              if(parseInt(mydata[j]['rating']) == '2'){
                                  bar2 += 1;
                              }
                              if(parseInt(mydata[j]['rating']) == '3'){
                                  bar3 += 1;
                              }
                              if(parseInt(mydata[j]['rating']) == '4'){
                                  bar4 += 1;
                              }
                              if(parseInt(mydata[j]['rating']) == '5'){
                                  bar5 += 1;
                              }
                          }
                          $('.bar-1').css('width', bar1+'%');
                          $('.bar-2').css('width', bar2+'%');
                          $('.bar-3').css('width', bar3+'%');
                          $('.bar-4').css('width', bar4+'%');
                          $('.bar-5').css('width', bar5+'%');
                      })
                      .catch(err =&gt; {
                          console.log(err)
  
                      });
                  },
  </code></pre>
  
  <p>TypeError: Cannot read property 'length' of undefined     at listToStyles.js:26</p>
  
  <p>Hope you guys give me some advice! </p>