Skip to content

Instantly share code, notes, and snippets.

@dniccum
Created October 4, 2018 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dniccum/52feec0f343b1bae08b2035d158ebfbe to your computer and use it in GitHub Desktop.
Save dniccum/52feec0f343b1bae08b2035d158ebfbe to your computer and use it in GitHub Desktop.
A Vue.JS directive that toggles the input type from text to password on blur; creating a secure input.
import Vue from 'vue';
Vue.directive('secure-input', {
inserted(el) {
el.type = 'password';
},
bind(el) {
el.addEventListener('focus', () => {
el.type = 'text'
});
el.addEventListener('blur', () => {
el.type = 'password'
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment