gpt4 book ai didi

reactjs - 错误 : [mobx] Computed values are not allowed to cause side effects by changing observables that are already being observed. 试图修改:

转载 作者:行者123 更新时间:2023-12-05 07:18:44 24 4
gpt4 key购买 nike

我正在尝试为过滤事件添加和删除上传的 gif 图片

我哪里失败了?

    @observable loading = false; //Loading variable being tracked in component
@computed get filtered() {
this.loading=true;//true
let filteredList = this.list.filter(
item => item.data.some(
obj => obj.tr_x.toLowerCase().includes(this.filterTermValue)
)
);
this.loading=false;//false
if (filteredList.length)
return filteredList;
return this.list;
}

最佳答案

什么是@computed装饰?

它是一种缓存。如果参数没有改变,则不计算,只返回之前的计算值。

作为避免副作用的良好做法,那些 @computed 函数不能改变任何东西,只是计算幂等信息。

并且您需要查看堆栈调用以确保更改任何属性的代码未被 @computed 函数调用。

关于reactjs - 错误 : [mobx] Computed values are not allowed to cause side effects by changing observables that are already being observed. 试图修改:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58183786/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com