Vue Mixin Decorator

1.2.0 · abandoned · verified Sun Apr 19

This library provides decorators for applying Vue 2 mixins within a TypeScript codebase, specifically designed for use with `vue-class-component`. It allows developers to compose reusable functionalities into class-style Vue components using decorator syntax, enhancing type safety compared to traditional mixin usage. The current stable version is 1.2.0, with the last release in July 2019, indicating a halted development cadence. Key differentiators include its focus on TypeScript and decorators for Vue 2 mixin composition, drawing inspiration from `av-ts` and `vue-property-decorator`. The project explicitly states a hope for deprecation if its core functionality is absorbed by officially supported projects, suggesting it's not intended for long-term standalone development.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates defining a mixin with `@Mixin` and composing it into a class-style Vue component using `Mixins` helper, showcasing method and property access.

import Vue from 'vue';
import { Component, Mixin, Mixins } from 'vue-mixin-decorator';

// Define a mixin using the @Mixin decorator
@Mixin
class MyMixin extends Vue {
  message: string = 'Hello from Mixin!';

  created() {
    console.log('Mixin created hook fired. Message:', this.message);
  }

  mixinMethod() {
    console.log('Mixin method called. Message:', this.message);
  }
}

// Define a component that extends the mixin using Mixins helper
@Component
class MyComponent extends Mixins<MyMixin>(MyMixin) {
  created() {
    // Access mixin properties and methods directly
    this.mixinMethod();
    console.log('Component created hook fired. Mixin message:', this.message);
  }

  render(h) {
    return h('div', `Component Output: ${this.message}`);
  }
}

// Instantiate and mount the component
new MyComponent().$mount('#app');

view raw JSON →