Last active
June 15, 2018 21:38
-
-
Save semeleven/3603504a0205253920c2eaa9b0db0dc6 to your computer and use it in GitHub Desktop.
Element ui email mask input vue directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createTextMaskInputElement } from 'text-mask-core'; | |
import emailMask from 'text-mask-addons/dist/emailMask'; | |
function inputHandler(el) { | |
el.textMaskInputElement.update(el.value); | |
el.dispatchEvent(new Event('input')); | |
} | |
function setupTextMask(outEl) { | |
const el = outEl; | |
el.textMaskInputElement = createTextMaskInputElement({ | |
inputElement: el, | |
guide: true, | |
mask: emailMask, | |
}); | |
inputHandler(el); | |
} | |
function getInput(el) { | |
return el.querySelector('.el-input__inner'); | |
} | |
export default { | |
inserted(el) { | |
setupTextMask(getInput(el)); | |
}, | |
update(el) { | |
inputHandler(getInput(el)); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you add exsample how to use it ?