Vue Functions

2.0.6 · maintenance · verified Sun Apr 19

This package, `vue-functions` (current stable version 2.0.6, last published in June 2020), provides a collection of utility functions and mixins specifically designed for Vue.js 2 applications. It offers features such as `updatablePropsEvenUnbound` for managing component props, `watchAsync` for watching asynchronous dependencies, reactive `windowSize` access via a mixin, and a `hookHelper` for extending component lifecycle hooks. Due to its foundational reliance on Vue 2's mixin system, it is not directly compatible with Vue 3's Composition API without significant refactoring or the use of Vue's compatibility build. The package's release cadence appears irregular, and its primary utility lies in streamlining common patterns within Vue 2 projects. Vue 2 itself officially reached End-of-Life on December 31st, 2023, making this package primarily relevant for maintaining legacy Vue 2 applications.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates `updatablePropsEvenUnbound` for managing local state from a prop and the reactive `windowSize` mixin within a Vue 2 component.

<template>
  <div>
    <p>Prop 'initialValue': {{ initialValue }}</p>
    <p>Local state 'currentValue': {{ currentValue }}</p>
    <button @click="currentValue++">Increment Local Value</button>
    <p>Window Inner Width: {{ windowSize.innerWidth }}px</p>
    <p>Window Inner Height: {{ windowSize.innerHeight }}px</p>
  </div>
</template>

<script lang="ts">
import Vue from 'vue';
import { updatablePropsEvenUnbound, windowSize } from 'vue-functions';

export default Vue.extend({
  name: 'MyComponent',
  // Use updatablePropsEvenUnbound to make 'initialValue' behave like v-model locally
  mixins: [
    updatablePropsEvenUnbound({
      initialValue: { localName: 'currentValue' }, // Maps 'initialValue' prop to 'currentValue' data property
    }),
    windowSize, // Provides reactive windowSize object
  ],
  props: {
    initialValue: {
      type: Number,
      default: 10,
    },
  },
  data() {
    return {
      // currentValue will be initialized from initialValue prop
      // and can be updated locally without mutating the prop directly.
      // windowSize is provided by the mixin and is reactive.
    };
  },
  mounted() {
    console.log('Component mounted. Initial local value:', (this as any).currentValue);
    console.log('Window size available (innerWidth):', (this as any).windowSize.innerWidth);
  },
  watch: {
    initialValue(newValue: number) {
      console.log('Prop initialValue changed to:', newValue);
    },
    currentValue(newValue: number) {
      console.log('Local currentValue changed to:', newValue);
      // You can emit an event here if you want to update the parent component
      // this.$emit('update:initialValue', newValue);
    },
  },
});
</script>

view raw JSON →