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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM