Created
May 4, 2018 12:34
-
-
Save qricambi/9c545ac9084eb6d5f2a7a80d04932716 to your computer and use it in GitHub Desktop.
Extend VTextField from vuetify that toggles password field visibility
This file contains hidden or 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
<script> | |
import VTextField from 'vuetify/es5/components/VTextField' | |
import VInput from 'vuetify/es5/mixins/input.js' | |
export default { | |
extends: VTextField, | |
data: () => { | |
return { | |
customAppendIcon: 'visibility_off', | |
customType: 'password' | |
} | |
}, | |
methods: { | |
genInput () { | |
let genInput = VTextField.methods.genInput.call(this) | |
genInput[0].data.attrs.type = this.customAppendIcon.includes('_off') ? 'password' : 'text' | |
return genInput | |
}, | |
genIcon (type, defaultCallback = null) { | |
let resultIcon = VInput.methods.genIcon.call(this, type, defaultCallback) | |
if (type === 'append')resultIcon.children[0].text = this.customAppendIcon | |
return resultIcon | |
} | |
}, | |
render () { | |
let that = this | |
return this.genInputGroup(this.genInput(), { attrs: { tabindex: false } }, () => { | |
if (that.customAppendIcon.includes('_off')) { that.customAppendIcon = 'visibility' } else { that.customAppendIcon = 'visibility_off' } | |
}) | |
} | |
} | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment