学习目标:
vue实现输入框密码的显示和隐藏
代码内容:
通过点击红心实现密码的显示和隐藏,初始默认为隐藏。
//template中代码:
<div class="pwd">
<label>密码:
<br />
</label>
<input type="password" name="passwd" v-if="show" placeholder="input the passwd">
<input type="text" name="passwd" v-else placeholder="input the passwd">
<div class="password-show" @click="pwd_show">❤</div>
</div>
//script中代码:
export default {
data(){
return{
show: true//初始为隐藏状态
}
},
methods:{
pwd_show:function(){//红心按钮定义方法
this.show = !this.show
},