vuejs / composition-api

Composition API plugin for Vue 2

Home Page:https://composition-api.vuejs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

watchEffect 的 onCleanUp 在 sync 模式下没有被调用

ivan-94 opened this issue · comments

commented

复现代码:

const count = ref(0)

watchEffect((onCleanup) => {
  const value = unref(count)
  console.log(value)

  onCleanup(() => {
     console.log('clean', value)
  })
}, {flush: 'sync'})

count.value++ // 期望 onCleanup 被同步执行

行为和 Vue 不一致

commented

原因是 Watcher 在 update 时,如果是 sync, 就会跳过 queueWatcher:

  update() {
    /* istanbul ignore else */
    if (this.lazy) {
      this.dirty = true
    } else if (this.sync) {
      this.run()
    } else {
      queueWatcher(this)
    }
  }

link

Stale issue message