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.
npm install vue-imaskVerified import paths — ran on the pinned version, not inferred.
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.
For Vue 3, explicitly use `v-model:masked`, `v-model:unmasked`, or `v-model:typed`. Handle specific event values via `onAccept:masked`, `onAccept:unmasked`, etc.
Install `npm i -D @vue/composition-api` for Vue 2, and `npm i -D @nuxtjs/composition-api` (plus module configuration) for Nuxt 2. This is not needed for Vue 3.
Always use ES module import syntax (`import ... from 'package';`). If you encounter issues in a CommonJS environment, ensure your build setup correctly handles dual-package exports or consider configuring your bundler to resolve the CJS entry point explicitly.
Update import paths to remove the redundant `/esm/` segment where applicable for cleaner and potentially more robust imports.
Instead of relying solely on `v-model` with the directive, use the `@accept` or `@complete` events to explicitly update your data property with `e.detail.value` or `e.detail.unmaskedValue`.
Run `npm install vue-imask` or `yarn add vue-imask` to install the package.
Install the necessary plugin: `npm install --save-dev @vue/composition-api`.
Access the mask reference via `e.detail` as `const maskRef = (e as CustomEvent).detail; this.value = maskRef.value;`.
Ensure `components: { 'imask-input': IMaskComponent }` is present in your component's options, and use it in the template as `<imask-input ... />`.