Skip to content

vue/no-watch-after-await

disallow asynchronously registered watch

  • ⚙️ This rule is included in all of "plugin:vue/essential", *.configs["flat/essential"], "plugin:vue/strongly-recommended", *.configs["flat/strongly-recommended"], "plugin:vue/recommended" and *.configs["flat/recommended"].

📖 Rule Details

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>
Now loading...

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>
Now loading...

🔧 Options

Nothing.

📚 Further Reading

🚀 Version

This rule was introduced in eslint-plugin-vue v7.0.0

🔍 Implementation