Skip to content

Files

Latest commit

 

History

History
59 lines (42 loc) · 1.25 KB

no-watch-after-await.md

File metadata and controls

59 lines (42 loc) · 1.25 KB

Pattern: Use of watch() after await expression

Issue: -

Description

This rule reports the watch() after await expression.
In setup() function, watch() should be registered synchronously.

<script>
import { watch } from 'vue'
export default {
  async setup() {
    /* ✓ GOOD */
    watch(watchSource, () => { /* ... */ })

    await doSomething()

    /* ✗ BAD */
    watch(watchSource, () => { /* ... */ })
  }
}
</script>

This rule is not reported when using the stop handle.

<script>
import { watch } from 'vue'
export default {
  async setup() {
    await doSomething()

    /* ✓ GOOD */
    const stopHandle = watch(watchSource, () => { /* ... */ })

    // later
    stopHandle()
  }
}
</script>

Further Reading