Vue Mixins Collection

0.3.6 · abandoned · verified Wed Apr 22

vue-mixins is a collection of reusable mixins designed for Vue.js applications, primarily targeting Vue 1.x and Vue 2.x versions. The package, currently at version 0.3.6 and last updated around 2020, includes utilities for DOM interaction (like `getViewportSize`, `onWindowResize`), event handling (`onClick`, `onDocument`), and state management (`isOpened`). Its policy states that mixins are never removed for deprecation; instead, if an API changes, the mixin's name is updated (e.g., `onResize` became `onResize2`). This reflects an older approach to code reuse in Vue, preceding the Composition API introduced in Vue 3. The package is effectively abandoned, lacking ongoing maintenance or compatibility updates for newer Vue versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate `onClick` and `getViewportSize` mixins into a Vue 2.x component using CommonJS `require` statements. It shows how the mixin's methods become available on the component instance.

const Vue = require('vue');
const onClickMixin = require('vue-mixins/onClick');
const getViewportSizeMixin = require('vue-mixins/getViewportSize');

new Vue({
  el: '#app',
  mixins: [
    onClickMixin,
    getViewportSizeMixin
  ],
  data: {
    message: 'Hello from Vue Mixins!',
    viewport: { width: 0, height: 0 }
  },
  methods: {
    onClick() {
      alert('Clicked! Viewport size: ' + JSON.stringify(this.getViewportSize()));
      console.log('Viewport size:', this.getViewportSize());
    }
  },
  created() {
    // getViewportSize is provided by getViewportSizeMixin
    this.viewport = this.getViewportSize();
    console.log('Component created. Current viewport:', this.viewport);
    window.addEventListener('resize', () => {
      this.viewport = this.getViewportSize();
    });
  },
  template: `
    <div>
      <h1>{{ message }}</h1>
      <p>Current Viewport: {{ viewport.width }}px x {{ viewport.height }}px</p>
      <button @click="click">Click me (via onClick mixin)</button>
      <p>Open console to see mixin methods in action.</p>
    </div>
  `
});

view raw JSON →