Skip to content

Instantly share code, notes, and snippets.

Last active May 6, 2021 21:04
What would you like to do?
Vue Js Hide/Show Password
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Show/hide Password</title>
<script src=""></script>
- How we can do that?: We can achieve that with toggle the type of input from 'text' to 'password' and versa on click.
- You can do that using Vanilla Js, Jquery or another framework.
<div id="app">
<div class="passwordDiv">
<!-- v-bind to bind data type from data instance -->
<input v-bind:type="fieldType" name="password" id="password" />
<button @click="switchInputTypes()">Show/Hide</button>
new Vue({
el: "#app",
data: {
text: "text",
fieldType: "password",
methods: {
switchInputTypes() {
// switch between two value taken from the data type
this.fieldType =
this.fieldType === "password" ? "text" : "password";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment