一、通过切换类名实现
1.html布局
<view class="content">
<view class="label">请输入退款密码</view>
<input v-model="params.pwd" placeholder="退款密码" :password="openPassword"/>
<view :class="[!openPassword ? 'psd-eye-active' : 'psd-eye']" @click="changePassword"></view>
</view>
2.样式部分(自己看着写)
.content{
position:relative;
.psd-eye-active{
width: 45rpx;
height: 45rpx;
background:url(../../../static/login/icon_turn.png) no-repeat center center;
position: absolute;
right: 50rpx;
top: 50%;
z-index:10;
}
.psd-eye{
width: 45rpx;
height: 45rpx;
background:url(../../../static/login/eye.png) no-repeat center center;
position: absolute;
right: 50rpx;
top: 50%;
z-index:10;
}
}
3.功能部分
<script>
data() {
return {
openPassword: true
}
},
methods: {
changePassword() {
this.openPassword = !this.openPassword;
}
}
</script>
二、通过图片路径切换
1.html布局
<view class="content">
<view class="label">请输入退款密码</view>
<input v-model="params.pwd" placeholder="退款密码" :password="openPassword"/>
<image class="psd-eye" :src="psdUrl" mode="aspectFill" @click="changePassword"></image>
</view>
2.样式部分(自己看着写)
.content{
position:relative;
.psd-eye{
width: 45rpx;
height: 45rpx;
position: absolute;
right: 50rpx;
top: 55%;
z-index:10;
}
}
3.功能部分文章来源:https://www.toymoban.com/news/detail-524672.html
<script>
data() {
return {
openPassword: true,
psdUrl:'../../../static/login/eye.png'
}
},
methods: {
changePassword() {
this.openPassword = !this.openPassword;
if(this.openPassword){
this.psdUrl = '../../../static/login/eye.png'
}else{
this.psdUrl = '../../../static/login/icon_turn.png'
}
}
}
</script>
展示图文章来源地址https://www.toymoban.com/news/detail-524672.html
到了这里,关于【vue2+uniapp】密码框输入密码显示和隐藏小功能(两种方法实现)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!