Vue Decorators for Vue 3 (Wrapper)

1.1.3 · abandoned · verified Sun Apr 19

`vue-decorator` (v1.1.3, last updated March 2022) aims to provide custom decorators compatible with Vue 3 by acting as a wrapper for `vue-class-component` and `vue-property-decorator`. However, the core dependencies it wraps are largely unmaintained or officially archived for Vue 3 compatibility. `vue-property-decorator` explicitly states it does not support Vue 3, and `vue-class-component` has been superseded by `vue-facing-decorator` for modern Vue 3 class component usage. Due to the unmaintained status of both `vue-decorator` itself and its underlying dependencies for Vue 3, it is not recommended for new projects. Developers should consider `vue-facing-decorator` or directly use Vue 3's Composition API, which is the idiomatic approach for current Vue development. This package has a very slow release cadence, with its last update over two years ago.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic Vue 3 class component using `@Component`, `@Prop`, `@Watch`, and `@Emit` decorators.

import { Component, Prop, Watch, Emit } from 'vue-decorator';
import { Vue } from 'vue-class-component'; // Vue 3 compatibility requires Vue from vue-class-component

@Component({
  template: `
    <div>
      <p>Hello, {{ userName }}!</p>
      <p>Count: {{ count }}</p>
      <button @click="increment">Increment</button>
      <input type="text" :value="message" @input="updateMessage(($event.target as HTMLInputElement).value)" />
      <p>Message: {{ message }}</p>
    </div>
  `
})
export default class MyComponent extends Vue {
  @Prop({ default: 'Guest' })
  readonly userName!: string;

  count: number = 0;
  message: string = 'Initial message';

  @Watch('count')
  onCountChanged(newValue: number, oldValue: number) {
    console.log(`Count changed from ${oldValue} to ${newValue}`);
  }

  @Emit('message-updated')
  updateMessage(value: string) {
    this.message = value;
    return value;
  }

  increment() {
    this.count++;
  }

  mounted() {
    console.log('Component mounted with user:', this.userName);
  }
}

view raw JSON →