Skip to content

watchEffect的使用 #265

@awangzhang

Description

@awangzhang

感谢作者提供的强大的工具,在使用过程中有点关于watchEffect的疑惑

※vue的文档中:watchEffect会在同步执行过程中,自动追踪所有能访问到的响应式属性。

例如以下这样的地方:
const hasAutoRun = ref(false)

watchEffect(() => {
if (!manual && fetchInstance.options.refreshDeps !== true) {
hasAutoRun.value = unref(ready)
}
})
watchEffect在同步执行过程中修改了hasAutoRun,很容易造成Maximum recursive updates exceeded in component警告。是不是加个不相等的判断或者改成watch更好?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions