1. 程式人生 > 實用技巧 >uni-app/小程式開發實現密碼輸入框密碼的可見與不可見切換按鈕,通過點選圖示實現

uni-app/小程式開發實現密碼輸入框密碼的可見與不可見切換按鈕,通過點選圖示實現

<view class="input-item">
                    <view class="img">
                        <image src="../../static/icons/password.png" mode=""></image>
                    </view>
                    <view class="input-acc">
                        <input type="password"
v-if="isShow" placeholder="輸入您的密碼" placeholder-style="color:#FFFFFF" @input="hidePassword" :value="password" maxlength="16" /> <input type="text" v-else placeholder="輸入您的密碼" placeholder-style="color:#FFFFFF" @input="password" :value="password" maxlength="16" /> </
view> <view class="see"> <image :src="isShow?'../../static/icons/not-show.png':'../../static/icons/show-words.png'" @tap="showPassword" mode="aspectFit" style="width:40rpx;height:40rpx"></image> </view
> </view>
//編輯判斷錯誤輸入的提示資訊(未完成)
<
view class="error-text" v-if="errorTips==1"><text class="warning-icon">!</text>{{i18n.usernameWarn}}</view>
data() {
            return {
                isShow: true,
                inputType: "password",
                password: "",
            };
        },
methods: {
            //輸入密碼
            password(e){
                this.password = e.detail.value;
                // this.$apply();
            },
            //輸入密碼
            hidePassword(e){
                this.password = e.detail.value;
                // this.$apply();
            },
            // 點選小眼睛圖示切換
            showPassword(){
                if(this.isShow){
                    this.isShow = false;
                    this.inputType = "text";
                    this.$apply();
                }else{
                    this.isShow = true;
                    this.inputType = "password";
                    this.$apply();
                }
            },
        }
/* 輸入框 */
.input{
    margin: 20rpx;
}
.input .input-item{
    display: flex;
    color: #FFFFFF;
    padding: 20rpx;
    border-bottom: 1rpx solid #e5e5e5;
    margin-top: 50rpx;
}
.input .input-item .img{
    margin-right: 30rpx;
}
.input .input-item .img image{
    width: 46rpx;
    height: 46rpx;
    
}
.input .input-item .input-acc{
    width: 100%;
}

.input .input-item .icon image{
    width: 40rpx;
    height: 40rpx;
    /* float: right; */
}

參考:https://www.cnblogs.com/jikeyun/p/12372293.html