vue-the-mask 为Vue.js创建的轻量级(2KB gzipped)和无依赖关系的掩码输入
vue-the-mask 为Vue.js创建的轻量级(2KB gzipped)和无依赖关系的掩码输入
JavaScript 表单输入控件
共1253Star
详细介绍
The Mask
A lightweight (2KB gzipped) and dependency free mask input created specific for Vue.js
Docs and Demo
JsFiddle
Install
yarn add vue-the-mask
or
npm i -S vue-the-mask
Usage (two flavors)
Global
import VueTheMask from 'vue-the-mask'
Vue.use(VueTheMask)
Local (inside the component)
import {TheMask} from 'vue-the-mask'
export default {
components: {TheMask}
}
Local (as directive)
import {mask} from 'vue-the-mask'
export default {
directives: {mask}
}
Tokens
'#': {pattern: /\d/},
'X': {pattern: /[0-9a-zA-Z]/},
'S': {pattern: /[a-zA-Z]/},
'A': {pattern: /[a-zA-Z]/, transform: v => v.toLocaleUpperCase()},
'a': {pattern: /[a-zA-Z]/, transform: v => v.toLocaleLowerCase()},
'!': {escape: true}
Properties
Property | Required | Type | Default | Description |
---|---|---|---|---|
value | false | String | Input value or v-model | |
mask | true | String, Array | Mask pattern | |
masked | false | Boolean | false | emit value with mask chars, default is raw |
placeholder | false | String | Same as html input | |
type | false | String | 'text' | Input type (email, tel, number, ...) |
tokens | false | Object | tokens | Custom tokens for mask |
What about money?
We understand that money format is a totally different domain, which needs another specific component. You can use https://github.com/vuejs-tips/v-money
Other Solutions
https://github.com/nosir/cleave.js
https://github.com/text-mask/text-mask
https://github.com/igorescobar/jQuery-Mask-Plugin
https://github.com/fernandofleury/vanilla-masker
https://github.com/angular-ui/ui-mask
https://github.com/insin/inputmask-core
https://github.com/niksmr/vue-masked-input
https://github.com/probil/v-mask
https://github.com/moip/awesome-mask
https://github.com/the-darc/string-mask
https://github.com/romulobrasil/PureMask.js
https://github.com/devindex/vue-mask
Currency
https://github.com/vuejs-tips/v-money
https://github.com/plentz/jquery-maskmoney
https://github.com/flaviosilveira/Jquery-Price-Format
https://github.com/kevinongko/vue-numeric
Suggest another one here
Contribution
You're free to contribute to this project by submitting issues and/or pull requests. This project is test-driven, so keep in mind that every change and new feature should be covered by tests. Your name will be added to the hall of fame ;)
License
This project is licensed under MIT License