script/no-deprecated-events-api
Disallow the removed Vue 2 events API ($on / $off / $once)
Default severity: error
Presets: none
Automatic fix: None; review the suggested change
Applies to: JS/TS scripts in Vue SFCs; examples show the relevant Options API or script setup form
Options: No rule-specific options. Severity and preset selection are configurable.
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({
lint: {
vize: {
"preset": "incremental",
"rules": {
"script/no-deprecated-events-api": "error"
}
},
},
});
vp run lint
Bad
The $on, $once, and $off calls use the instance event-bus methods removed in Vue 3.
<script setup lang="ts">
this.$on('event', handler)
this.$once('event', handler)
this.$off('event', handler)
emitter.$off('event')
</script>
Good
$emit remains valid, while event-bus subscription moves to the external emitter’s on method. The repair separates parent-directed emission from an external event bus.
<script setup lang="ts">
// $emit is still valid in Vue 3
this.$emit('event', payload)
// Use an external emitter instead
import mitt from 'mitt'
const emitter = mitt()
emitter.on('event', handler)
</script>
Good avoids this rule's finding under the configuration above; other rules may still report diagnostics.