Registry / web-framework / vue-facing-decorator

vue-facing-decorator

JSON →
library4.0.1jsnpmunverified

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-decorator
INSTALL
IMPORT
SIG · VUE-FACING-DECORAT
V
vue-facing-decorator
web-frameworkjavascriptv4.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Component
import { Component } from 'vue-facing-decorator'
import Component from 'vue-facing-decorator'
The primary decorator used to designate a class as a Vue component. It is a named export.
Vue
import { Vue } from 'vue-facing-decorator'
import Vue from 'vue'
This is the base class that your component classes should extend. Note that it is imported from 'vue-facing-decorator', not directly from 'vue'.
Prop
import { Prop } from 'vue-facing-decorator'
The decorator used for defining reactive component properties. Other common decorators like `@Emit`, `@Ref`, `@Watch`, `@Provide`, and `@Inject` are also named exports from this package.
toNative
import { toNative } from 'vue-facing-decorator'
const MyComponent = new MyClassComponent().$options
Since v3.0.0, this utility function is required to transform a class component into a Vue Options API object, making it compatible with Vue's component registration system (e.g., `app.component` or the `components` option).

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.

import { createApp } from 'vue'; import { Component, Prop, Vue, toNative } from 'vue-facing-decorator'; @Component({ name: 'GreetingDisplay', emits: ['greeted'] }) class GreetingDisplay extends Vue { @Prop({ type: String, default: 'World' }) readonly name!: string; message: string = 'Hello'; get fullGreeting(): string { return `${this.message}, ${this.name}!`; } sayHello(): void { console.log(this.fullGreeting); this.$emit('greeted', this.fullGreeting); } // Example lifecycle hook mounted(): void { this.sayHello(); console.log('GreetingDisplay component mounted.'); } } // Create Vue app instance and register the class component const app = createApp({ template: ` <div id="app-root"> <h1>Vue Facing Decorator Example</h1> <greeting-display :name="'Developer'" @greeted="handleGreeted" /> <greeting-display /> </div> `, components: { // Convert the class component to a native Vue options API component for registration GreetingDisplay: toNative(GreetingDisplay) }, methods: { handleGreeted(msg: string) { console.log('Component greeted:', msg); } } }); app.mount('#app'); // To run this, you would typically have an index.html file with a div#app element: // <div id="app"></div>
Debug
Known issues
breakingSince v3.0.0, class components created with `vue-facing-decorator` must be explicitly converted to standard Vue Options API objects using the `toNative()` function before they can be registered globally or used within a parent component's `components` option.
fix
Always wrap your class components with `toNative()` when registering them, e.g., `components: { MyComponent: toNative(MyClassComponent) }`.
affects: >=3.0.0
breakingVersion 3.0.0 introduced support for the Stage 3 Decorators API. This necessitates using TypeScript 5.x or newer and setting `compilerOptions.experimentalDecorators` to `false` in your `tsconfig.json`. Previously, for Stage 2 decorators, `experimentalDecorators` needed to be `true`.
fix
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`.
affects: >=3.0.0
gotchaWhile v3.0.0 supports TypeScript 5.x and Stage 3 decorators, the release notes mention potential compatibility issues with certain Vue tooling, such as Volar, at the time of release. Always verify your development environment's compatibility.
fix
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.
affects: >=3.0.0
gotchaAll exported symbols from `vue-facing-decorator`, including the `Vue` base class and all decorators (`@Component`, `@Prop`, `@Emit`, etc.), are named exports. Attempting to use default imports or CommonJS `require()` for individual symbols will likely result in undefined values or errors in modern ESM environments.
fix
Always use named imports: `import { Component, Vue, Prop } from 'vue-facing-decorator';`. For CommonJS, destructure the `require` result.
affects: >=3.0.0
Errors
Common errors & fixes
Failed to resolve component: MyComponent
A class-based component was not correctly transformed using `toNative()` before being registered with Vue, leading Vue to not recognize it as a valid component option.
fix
When defining your components object, ensure you wrap your class component: `components: { MyComponent: toNative(MyClassComponent) }`.
Decorators are not enabled. Try compiling with the 'experimentalDecorators' compiler option.
TypeScript's support for decorators is not correctly configured in your `tsconfig.json` for the specific decorator API stage you are using.
fix
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`.
TypeError: Cannot read properties of undefined (reading '$emit')
Attempting to access Vue instance properties (like `this.$emit`, `this.$refs`, `this.$slots`) in a context where `this` is not correctly bound to the Vue component instance, or before the component has been fully initialized and mounted.
fix
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.
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies
vuerequiredRuntime dependency for all Vue 3 component features, as this library builds on top of Vue's core.
Agent activity
31 hits · last 30 days
node
26
OpenAI (training)
1
Resources