Vue Facing Decorator (vue-facing-decorator) is a library that enables class-based component syntax and TypeScript decorators for Vue 3 applications, offering an alternative to the standard Options API or Composition API without `<script setup>`. Currently at version 4.0.1, it provides a familiar development experience for developers accustomed to `vue-class-component` or `vue-property-decorator` in Vue 2, but specifically engineered for Vue 3. The library maintains an active release cadence, with several minor and patch updates in its 3.x series and a recent major jump to 4.x. Key differentiators include its compatibility with both the Stage 2 and the newer Stage 3 Decorators API (requiring specific TypeScript configurations), robust support for ES class inheritance, Vue's `extends`, and `mixins` features, and a performance-optimized transformation process that converts ES classes to Vue Options API during project loading. It aims to be a safe and specification-compliant transformer, serving as a community-desired solution for class-based Vue 3 components.
npm install vue-facing-decoratorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a class-based Vue 3 component using `@Component` and `@Prop` decorators, including lifecycle methods and a computed property. It also illustrates how to register and use the component within a standard Vue application by converting it to the native Options API format with the `toNative` utility.
Always wrap your class components with `toNative()` when registering them, e.g., `components: { MyComponent: toNative(MyClassComponent) }`.For Stage 3 decorators with TypeScript 5.x+, ensure `compilerOptions.experimentalDecorators: false` and `compilerOptions.useDefineForClassFields: true`. For older TypeScript versions and Stage 2 decorators, set `compilerOptions.experimentalDecorators: true`.
Consult the official documentation for `vue-facing-decorator` and your specific Vue tooling (e.g., Volar, Vue CLI) for the latest recommendations regarding TypeScript versions and decorator configurations. Consider sticking to Stage 2 decorators or a specific TS version if tooling stability is paramount.
Always use named imports: `import { Component, Vue, Prop } from 'vue-facing-decorator';`. For CommonJS, destructure the `require` result.When defining your components object, ensure you wrap your class component: `components: { MyComponent: toNative(MyClassComponent) }`.For Stage 2 decorators (older TypeScript), set `compilerOptions.experimentalDecorators: true`. For Stage 3 decorators (TypeScript 5.x+), set `compilerOptions.experimentalDecorators: false` and `compilerOptions.useDefineForClassFields: true`.
Ensure that methods accessing Vue instance properties are defined within the component class and that the component is properly mounted before these properties are accessed. Be mindful of how `this` context is handled, especially with arrow functions or external utility functions.