Created
March 19, 2019 05:33
-
-
Save warrickbayman/43ce8e06bca7e5e383ce5fc3ca27eea2 to your computer and use it in GitHub Desktop.
Simple Vue password input component.
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
<template> | |
<div class="input-group password-input"> | |
<input type="hidden" :name="name" v-model="password" /> | |
<input type="password" class="form-control" v-model="password" v-if="!visible" /> | |
<input type="text" class="form-control" v-model="password" v-else /> | |
<div class="input-group-append"> | |
<button class="btn btn-outline-dark" type="button" @click.prevent="toggleVisibility"> | |
<i class="material-icons"> | |
<template v-if="visible">visibility</template> | |
<template v-else>visibility_off</template> | |
</i> | |
</button> | |
</div> | |
</div> | |
</template> | |
<script> | |
export default { | |
props: { | |
name: String, | |
value: String, | |
}, | |
data () { | |
return { | |
visible: false, | |
password: this.value, | |
} | |
}, | |
watch: { | |
password () { | |
this.$emit('input', this.password); | |
} | |
}, | |
methods: { | |
toggleVisibility () { | |
this.visible = !this.visible; | |
} | |
} | |
} | |
</script> | |
<style scoped> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment