mirror of
https://github.com/vuejs/vue.git
synced 2024-11-21 20:28:54 +00:00
parent
012e10c9ca
commit
8904ca77c2
@ -320,8 +320,8 @@ function doWatch(
|
||||
} else {
|
||||
// pre
|
||||
watcher.update = () => {
|
||||
if (instance && instance === currentInstance) {
|
||||
// pre-watcher triggered inside setup()
|
||||
if (instance && instance === currentInstance && !instance._isMounted) {
|
||||
// pre-watcher triggered before
|
||||
const buffer = instance._preWatchers || (instance._preWatchers = [])
|
||||
if (buffer.indexOf(watcher) < 0) buffer.push(watcher)
|
||||
} else {
|
||||
|
@ -1116,4 +1116,24 @@ describe('api: watch', () => {
|
||||
await nextTick()
|
||||
expect(order).toMatchObject([`mounted`, `watcher`])
|
||||
})
|
||||
|
||||
// #12624
|
||||
test('pre watch triggered in mounted hook', async () => {
|
||||
const spy = vi.fn()
|
||||
new Vue({
|
||||
setup() {
|
||||
const c = ref(0)
|
||||
|
||||
onMounted(() => {
|
||||
c.value++
|
||||
})
|
||||
|
||||
watchEffect(() => spy(c.value))
|
||||
return () => {}
|
||||
}
|
||||
}).$mount()
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
await nextTick()
|
||||
expect(spy).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user