Skip to content

vue/no-watch-after-await

禁止异步注册watch

为什么

setup()函数中, watch()应该被同步注册。

建议

await表达式之后不要使用watch()

错误示例

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

    watch('ranwawa', () => {
      /* ... */
    });
  }
};
</script>
<script>
import { watch } from 'vue';
export default {
  async setup() {
    await doSomething();

    watch('ranwawa', () => {
      /* ... */
    });
  }
};
</script>

正确示例

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

    await doSomething();
  }
};
</script>
<script>
import { watch } from 'vue';
export default {
  async setup() {
    watch('ranwawa', () => {
      /* ... */
    });

    await doSomething();
  }
};
</script>

参考