Skip to content

noVueDeprecatedEventsApi (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noVueDeprecatedEventsApi": "error"
}
}
}
}

Disallow the Vue $on, $off, and $once instance methods.

Vue 3 removed the $on, $off, and $once methods from component instances, so a component can no longer listen to its own events with them. Calling one of these methods throws an error, because the method doesn’t exist.

To react to an event that a child component emits, listen to it with v-on (or @) in the parent’s template. To send events between components that aren’t parent and child, use a small event library such as mitt or tiny-emitter.

This rule checks calls on this, and on variables declared with const vm = this, inside the options object of a component: the default export of a .vue file, or the object passed to defineComponent() or createApp(). Calls written as this.$on?.() are allowed, because they only run when the method exists.

See the Vue 3 migration guide for more information.

<script>
export default {
mounted() {
this.$on("start", () => {
console.log("start");
});
},
};
</script>
code-block.vue:4:10 lint/nursery/noVueDeprecatedEventsApi ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The Vue $on instance method was removed in Vue 3.

2 │ export default {
3 │ mounted() {
> 4 │ this.$on("start", () => {
│ ^^^
5 │ console.log("start");
6 │ });

ℹ Component instances no longer have this method, so calling it throws an error.

ℹ Listen to a child component's events with v-on in the parent's template, or use an event library such as mitt. See the Vue 3 migration guide for more information.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

import { defineComponent } from "vue";
export default defineComponent({
beforeUnmount() {
this.$off("start");
},
});
code-block.js:5:10 lint/nursery/noVueDeprecatedEventsApi ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The Vue $off instance method was removed in Vue 3.

3 │ export default defineComponent({
4 │ beforeUnmount() {
> 5 │ this.$off("start");
│ ^^^^
6 │ },
7 │ });

ℹ Component instances no longer have this method, so calling it throws an error.

ℹ Listen to a child component's events with v-on in the parent's template, or use an event library such as mitt. See the Vue 3 migration guide for more information.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

<script>
import mitt from "mitt";
const emitter = mitt();
export default {
mounted() {
emitter.on("start", () => {
console.log("start");
});
this.$emit("ready");
},
};
</script>