我是 VueJS 的新手,我收到了来自 Vue 的警告,
[Vue warn]: You may have an infinite update loop in a component render function.
当我在 V-bind:style 中使用 V-for 变量时,这是一个示例:在模板中:
<div v-for="item in model.items" v-bind:class="test(item.result)">
{{item.id}}
</div>
在脚本中:
data() {
return {
accept: false,
not_accept: false,
};
},
methods: {
test(result) {
if (result == 'accept') {
this.accept = true;
this.not_accept = false;
} else if (result == 'Not accept') {
this.accept = false;
this.not_accept = true;
} else {
console.log(result);
}
return {
success: this.accept,
danger: this.not_accept,
};
},
},
原文由 ramzi trabelsi 发布,翻译遵循 CC BY-SA 4.0 许可协议
@Decade 对这个问题是正确的。这是确切的问题:
test
的结果绑定类,该函数有缺陷,因为它再次尝试改变状态,从而导致渲染 - 测试 - 渲染循环。您可以通过使您的测试函数不改变状态来解决此问题,如下所示:
我希望这有帮助!