Categories
Vue Answers

How to use mask in a Vue.js Vuetify text field?

Spread the love

Sometimes, we want to use mask in a Vue.js Vuetify text field.

In this article, we’ll look at how to use mask in a Vue.js Vuetify text field.

How to use mask in a Vue.js Vuetify text field?

To use mask in a Vue.js Vuetify text field, we can use the v-mask package.

To install it, we run

npm install v-mask

Then in main.js, we register the directive globally with

import { VueMaskDirective } from "v-mask";
Vue.directive("mask", VueMaskDirective);

Then we use it with v-text-field by writing

<template>
  <div>
    <v-text-field
      v-mask="'###.###.###-##'"
      :value="currentValue"
      @input="handleInput"
    />
  </div>
</template>

We set v-mask to the mask we want.

Conclusion

To use mask in a Vue.js Vuetify text field, we can use the v-mask package.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *