Mask components to vuetify 2
npm install vuetify-mask
$ npm install vuetify-mask --save
`Register
1- Create a file src/plugins/vuetify-mask.js with:
import Vue from "vue";
import VuetifyMask from "vuetify-mask";
Vue.use(VuetifyMask);
export default VuetifyMask;2- Add in src/mains.js file:
import "./plugins/vuetify-mask.js";
Properties (v-bind:properties)
You can add any v-text-field property
v-text-field properties. Properties that have hyphens (single-line, background-color...) should be changed as follows:
v-bind:properties="{
singleLine: true,
backgroundColor: 'red'
}"
or
v-bind:properties="{
'single-line': true,
'background-color': 'red'
}"
Options (v-bind:options)
| Option | Component | Default | Description |
| ------------ | ------------ | ------------ | ------------ |
| inputMask | Money, Percent, Integer, DateTime, SimpleMask | | mask that will be applied in the v-text-field |
| outputMask | Money, Percent, Integer, SimpleMask, CPF, CNPJ, CEP | | mask that will be applied in the v-model |
| empty | Money, Percent, Integer, DateTime, SimpleMask, CPF, CNPJ, CEP, DotNumber | "" | Value in v-model when v-text-field is empty. Can be null, "" or other|
| applyAfter | Integer, SimpleMask, CPF, CNPJ, CEP, DotNumber| | The value is masked only after all typing |
| alphanumeric | SimpleMask | false | |
| lowerCase| SimpleMask | false | |
| acceptFile| FileBase64 | image/* | Sets the file type to convert to base64 |
Events
| Event | value | Description |
| ------------ | ------------ | ------------ |
| blur | Event | Emitted when the input is blurred |
| change | any | Emitted when the input is changed by user interaction |
| click | MouseEvent | Emitted when input is clicked |
| focus | Event | Emitted when component is focused |
| keydown | KeyboardEvent | Emitted when any key is pressed |
| mousedown | MouseEvent | Emitted when click is pressed |
| mouseup | MouseEvent | Event mouseup |How to use
$3
`
v-model="value"
v-bind:label="label"
v-bind:properties="{
prefix: 'R$',
readonly: false,
disabled: false,
outlined: false,
clearable: true,
placeholder: ' ',
}"
v-bind:options="{
locale: 'pt-BR',
length: 11,
precision: 6,
empty: null,
}"
/>
`$3
`
v-model="value"
v-bind:label="label"
v-bind:properties="{
suffix: '%',
readonly: false,
disabled: false,
outlined: false,
clearable: true,
placeholder: '',
}"
v-bind:options="{
locale: 'pt-BR',
length: 3,
precision: 2,
empty: null,
}"
/>
`$3
`
v-model="value"
v-bind:label="label"
v-bind:properties="{
readonly: false,
disabled: false,
outlined: false,
clearable: true,
placeholder: '',
}"
v-bind:options="{
inputMask: '#########',
outputMask: '#########',
empty: null,
applyAfter: false,
}"
v-bind:focus="focus"
v-on:focus="focus = false"
/>
`$3
works in milliseconds
`
v-model="value"
v-bind:label="label"
v-bind:properties="{
readonly: false,
disabled: false,
outlined: false,
clearable: true,
placeholder: 'YYYY-MM-DD HH:mm:ss',
'prepend-icon': 'mdi-calendar',
}"
v-bind:options="{
inputMask: 'YYYY-MM-DD HH:mm:ss',
empty: null,
}"
v-bind:focus="focus"
v-on:focus="focus = false"
/>
`
$3
works in milliseconds
`
v-model="value"
label="Date Time"
v-bind:properties="{
backgroundColor: '#EEE9E9',
clearable: false,
outlined: true,
prependIcon: 'mdi-calendar',
appendIcon: 'mdi-av-timer',
}"
v-bind:options="{
tabDateTitle: 'Date',
tabTimeTitle: 'Time',
tabBackgroundColor: 'green',
locale: 'en-US',
format: 'YYYY-MM-DD',
closeOnDateClick: false,
useSeconds: false,
}"
/>
`$3
`
v-model="value"
v-bind:label="label"
v-bind:properties="{
prefix: '',
suffix: '',
readonly: false,
disabled: false,
outlined: false,
clearable: true,
placeholder: '',
}"
v-bind:options="{
inputMask: '#### #### #### ####',
outputMask: '################',
empty: null,
applyAfter: false,
alphanumeric: true,
lowerCase: false,
}"
v-bind:focus="focus"
v-on:focus="focus = false"
/>
`$3
`
v-model="value"
v-bind:label="label"
v-bind:properties="{
prefix: '',
suffix: '',
readonly: false,
disabled: false,
outlined: false,
clearable: true,
placeholder: '',
}"
v-bind:options="{
inputMask: '(##) #####-####',
outputMask: '###########',
empty: null,
applyAfter: false,
alphanumeric: true,
lowerCase: false,
}"
v-bind:focus="focus"
v-on:focus="focus = false"
/>
`$3
You can create your masks.
`
v-model="value"
v-bind:label="label"
v-bind:properties="{
prefix: '',
suffix: '',
readonly: false,
disabled: false,
outlined: false,
clearable: true,
placeholder: '',
}"
v-bind:options="{
inputMask: '##-####-####-###',
outputMask: '##-####-####-###',
empty: null,
applyAfter: false,
alphanumeric: true,
lowerCase: false,
}"
v-bind:focus="focus"
v-on:focus="focus = false"
/>
`$3
Convert files to base 64.
`
v-model="value"
v-bind:label="label"
v-bind:properties="{
outlined: true,
placeholder: ' ',
appendIcon:'mdi-message-image-outline',
}"
v-bind:options="{
acceptFile:'image/*',
}"
v-on:fileName="fileName = $event"
/>
Other acceptFile options:
acceptFile:'image/*'
acceptFile:'application/pdf'
acceptFile:'image/jpeg,image/gif,image/png,application/pdf'
acceptFile:'image/jpeg,image/gif,image/png,application/pdf,image/x-eps'
`$3
Accept only dot and numbers.
`
v-model="value"
v-bind:label="label"
v-bind:properties="{
readonly: false,
disabled: false,
outlined: false,
clearable: true,
placeholder: '',
}"
v-bind:options="{
length: 20,
empty: null,
applyAfter: false,
}"
/>
`
$3
brazilian mask
`
v-model="value"
v-bind:label="label"
v-bind:properties="{
readonly: false,
disabled: false,
outlined: true,
clearable: true,
placeholder: '',
}"
v-bind:options="{
outputMask: '###########',
empty: null,
applyAfter: true,
}"
v-bind:focus="focus"
v-on:focus="focus = false"
/>
`$3
brazilian mask
`
v-model="value"
v-bind:label="label"
v-bind:properties="{
disabled: false,
outlined: true,
clearable: true,
placeholder: '',
}"
v-bind:options="{
outputMask: '##############',
empty: null,
applyAfter: true,
}"
v-bind:focus="focus"
v-on:focus="focus = false"
/>
`$3
brazilian mask
`
v-model="value"
v-bind:label="label"
v-bind:properties="{
disabled: false,
outlined: true,
clearable: true,
placeholder: '',
}"
v-bind:options="{
outputMask: '########',
empty: null,
applyAfter: true,
}"
v-bind:focus="focus"
v-on:focus="focus = false"
/>
``