Skip to content

watchEffect BUG #9408

Closed
Closed
@llch20181014

Description

@llch20181014

Vue version

3.3.4

Link to minimal reproduction

https://cn.vuejs.org/api/reactivity-core.html#watcheffect

Steps to reproduce

import { ref, watchEffect } from 'vue'
const r = ref(0)
function sleep(time){ return new Promise((resolve)=>{ setTimeout(() => { resolve() }, time); }) }
watchEffect(async ()=>{
await sleep(500)
console.log('watch1',r.value)
})
setTimeout(() => { r.value = 2 }, 3000);

What is expected?

Should listen for changes in r

What is actually happening?

Only printed:
watch1 0

System Info

No response

Any additional comments?

I changed the code:
import { ref, watchEffect } from 'vue'
const r = ref(0)
function sleep(time){ return new Promise((resolve)=>{ setTimeout(() => { resolve() }, time); }) }
watchEffect(async ()=>{
console.log('watch1',r.value)
await sleep(500)
})
setTimeout(() => { r.value = 2 }, 3000);
Printed:
watch1 0
watch1 2

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