Vue IMask Plugin

7.6.1 · active · verified Sun Apr 19

vue-imask is the official Vue.js plugin for IMask.js, a robust and versatile JavaScript input mask library. It provides native Vue 2 and Vue 3 support through a component (`<imask-input>`), a directive (`v-imask`), and a composable (`useIMask`) for granular control over input formatting. The package is currently at version 7.6.1 and receives frequent updates, typically on a monthly basis, incorporating new mask features and bug fixes from the core IMask.js library, along with Vue-specific enhancements. Its key differentiators include comprehensive mask types (pattern, number, date, enum, dynamic, etc.), excellent IME support, and a flexible API that allows for both declarative (component/directive) and programmatic (composable) masking, making it suitable for a wide range of input formatting requirements in Vue applications. It ships with full TypeScript type definitions, ensuring type safety and improved developer experience.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the usage of the `IMaskComponent` with Vue 3's Composition API, showing `v-model:typed` for bidirectional binding and separate `accept` events for masked and unmasked values.

<template>
  <imask-input
    v-model:typed="numberModel"
    :mask="Number"
    radix="."
    @accept:masked="onAcceptMasked"
    @accept:unmasked="onAcceptUnmasked"
    placeholder='Enter number here'
  />
</template>

<script lang="ts">
  import { defineComponent, ref } from 'vue';
  import { IMaskComponent } from 'vue-imask';
  // Also useful: Number, Pattern, Date, Enum masks from imask core
  import { NumberMask } from 'imask'; 

  export default defineComponent({
    components: {
      'imask-input': IMaskComponent
    },
    setup() {
      const numberModel = ref<number | string>('');

      const onAcceptMasked = (value: string) => {
        console.log('Masked value:', value);
      };

      const onAcceptUnmasked = (unmaskedValue: string) => {
        console.log('Unmasked value:', unmaskedValue);
      };

      return {
        numberModel,
        Number: NumberMask, // Or simply 'Number' if importing from 'imask' core
        onAcceptMasked,
        onAcceptUnmasked,
      };
    }
  });
</script>

view raw JSON →