您可以在组件呈现功能中具有无限更新周期

我是新的b。 VueJS, 我有一个警告 Vue,


[Vue warn]: You may have an infinite update loop in a component render function.


当我使用变量 V-for 在 V-bind:style, 这是一个例子 :
在模板中 :


<div v-bind:class="test/item.result/" v-for="item in model.items">
{{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,
};
},
},
已邀请:

石油百科

赞同来自:

@Decade 此事的权利。 这是一个准确的问题:

你在方法中 render 使用某个状态值呈现元素列表

NOTE: 渲染方法在任何条件发生变化时都开始

然后您正在尝试根据函数的结果绑定类
test

此功能是错误的,因为它正在重新尝试突变状态,从而导致渲染周期 - 面团 - 渲染。

例如,您可以通过使测试函数变异状态来解决这个问题:


methods: {
test/result/ {
let accept;
if /result == 'accept'/ {
accept = true;
} else if /result == 'Not accept'/ {
accept = false;
} else {
console.log/result/;
}

return {
success: accept,
danger: !accept,
};
},
}


我希望它有所帮助!

江南孤鹜

赞同来自:

首先,我不确定 , 为什么你有
not_accept

, 你能刚用吗?
!this.accept

而不是他?

我不确定为什么你有这个警告,但我的想法。

观察者
v-bind:class

最糟糕的变化
item.result

,
this.accept


this.not_accept

. 这些值的任何变化都将导致事实上,在重复呼叫时将重新可视化。
test

. 但在...之内
test

你改变了
this.accept


this.not_accept

, 所以 Vue 应该再次检查一下 , 结果是否改变了,同时它可以

再次

改变
this.accept


this.not_accept

, 等等。

捆绑
class

并且数据是错误的。
class

对于每个项目,将安装同样的事情,但似乎您需要对每个项目的自定义样式取决于
item.result

. 你真的不应该改变任何属性
this

里面
test

.

很难给出一个详尽的答案,因为我不太确定你的组件如何工作以及他应该做的事情。

龙天

赞同来自:

如果您调用函数而不是在指令中传输函数,则可以收到此错误 vue. 这是一个例子:

我定制了
https://gist.github.com/jessli ... 2c1de
.

这不好:


v-on-show-bs-tab="getFirstPageSites//"


这里 vue, 显然,导致功能 /或者相反计算表达式/ 并传输指令的结果。

很好:


v-on-show-bs-tab="getFirstPageSites"


在这里,我按名称给出一个函数,以便我可以在指令中调用它。

要回复问题请先登录注册