JS.VUE.NEXT.TICK.STYLE

Enforce Promise or callback style in 'nextTick'

Rule Details

This rule enforces whether the callback version or Promise version (which was introduced in Vue v2.1.0) should be used in Vue.nextTick and this.$nextTick.

{'vue/next-tick-style': ['error']}

Copy
<script>
import { nextTick as nt } from 'vue';

export default {
  async mounted() {
    /* GOOD */
    nt().then(() => callback());
    await nt(); callback();
    Vue.nextTick().then(() => callback());
    await Vue.nextTick(); callback();
    this.$nextTick().then(() => callback());
    await this.$nextTick(); callback();

    /* BAD */
    nt(() => callback());
    nt(callback);
    Vue.nextTick(() => callback());
    Vue.nextTick(callback);
    this.$nextTick(() => callback());
    this.$nextTick(callback);
  }
}
</script>

Options

Default is set to promise.

Copy
{
  "vue/next-tick-style": ["error", "promise" | "callback"]
}
  • "promise" (default) ... requires using the promise version.
  • "callback" ... requires using the callback version. Use this if you use a Vue version below v2.1.0.

"callback"

{'vue/next-tick-style': ['error', 'callback']}

Copy
<script>
import { nextTick as nt } from 'vue';

export default {
  async mounted() {
    /* GOOD */
    nt(() => callback());
    nt(callback);
    Vue.nextTick(() => callback());
    Vue.nextTick(callback);
    this.$nextTick(() => callback());
    this.$nextTick(callback);

    /* BAD */
    nt().then(() => callback());
    await nt(); callback();
    Vue.nextTick().then(() => callback());
    await Vue.nextTick(); callback();
    this.$nextTick().then(() => callback());
    await this.$nextTick(); callback();
  }
}
</script>

Further Reading

  • Vue.nextTick API in Vue 2 (https://v2.vuejs.org/v2/api/#Vue-nextTick)
  • vm.$nextTick API in Vue 2 (https://v2.vuejs.org/v2/api/#vm-nextTick)
  • Global API Treeshaking (https://v3-migration.vuejs.org/breaking-changes/global-api-treeshaking.html)
  • Global nextTick API in Vue 3 (https://vuejs.org/api/general.html#nexttick)
  • Instance $nextTick API in Vue 3 (https://vuejs.org/api/component-instance.html#nexttick)

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/