Vue Class Decorator (current version 7.6.3) is a library that provides additional decorators for defining Vue 2 components using a class-based, TypeScript-first syntax. It extends the capabilities of `vue-class-component` and `vue-property-decorator` by introducing decorators for functional components (`@FunctionalVue`), filters (`@Filter`), event handling (`@On`, `@Once`), and lifecycle hooks (`@Mounted`). This approach allows developers to define components, methods, and lifecycle hooks as class properties and methods, leveraging TypeScript's strong typing. The library is specifically tailored for Vue 2 projects and does not support Vue 3, where the Composition API is the recommended approach for component definition. Its release cadence has slowed considerably, with no recent updates for Vue 3 compatibility, positioning it primarily for legacy Vue 2 maintenance.
npm install vue-class-decoratorVerified import paths — ran on the pinned version, not inferred.
Demonstrates the use of `@FunctionalVue`, `@Filter`, `@On`, and `@Mounted` decorators in a Vue 2 class-based component setup.
For Vue 3, migrate to the Composition API or explore `vue-facing-decorator` or `@haixing_hu/vue3-class-component` as alternatives.
If the method needs to be directly callable or accessible via `this.methodName`, ensure `reserve` is `true` (which is the default) or omit it. Only set `reserve: false` if the method is exclusively for internal event binding and should not be part of the public `methods` API.
Add or ensure the following compiler options in your `tsconfig.json`: `"experimentalDecorators": true, "emitDecoratorMetadata": true`.
For new projects or major refactoring, consider adopting the Vue 3 Composition API (`<script setup>`) to align with modern Vue development practices.
Ensure `vue-class-component` is installed (`npm install vue-class-component`) and correctly imported. Also, verify that `Vue` is imported from `vue-class-component` when defining your base class, or that `vue-class-decorator`'s re-exports are correctly handled.
In `tsconfig.json`, ensure `"experimentalDecorators": true` and `"emitDecoratorMetadata": true` are set under `compilerOptions`. If using Babel, ensure `@babel/plugin-proposal-decorators` and `@babel/plugin-proposal-class-properties` are configured.
Check the decorator settings, especially `reserve` for `@On`/`@Once`. Ensure all necessary types are correctly inferred. If it's a lifecycle hook, make sure it's decorated correctly (e.g., `@Mounted()`).