You may have an infinite update loop in a component render function

在写商城项目时写了一段垃圾代码

根据methods返回值,来设置元素的行内样式

//元素:
          <li>
            {{ shop.score[0].name }}
            <i :style="{ color: serviceScore(0) }">{{ shop.score[0].score }}</i>
            <i :style="{ backgroundColor: serviceScore(0) }">{{ score }}</i>
          </li>

//methods:
    serviceScore(i) {
      let scoreColor = null;
      if (this.shop.score[i].isBetter) {
        this.score = "高";
        scoreColor = "red";
      } else {
        this.score = "低";
        scoreColor = "#6aa44a";
      }
      return scoreColor;
    },

能正常显示,但是console内出现Vue警告

You may have an infinite update loop in a component render function

 

上一篇:Laravel框架一对一模型关联


下一篇:python+selenium+chrome 自动化测试TPshop商城项目实战(二)——通过cookies绕过验证码以及添加商品到购物车