用vue写原生input密码框的文字显示/隐藏,通过v-if判断或改变type属性实现

13 篇文章 0 订阅

要通过vue根据所提供的图片点击时显示/隐藏密码框的内容!

效果图

 

方法一:

 通过点击最右边的图标来实现,可以结合vue的v-if ,v-else判断加点击事件完成。

//表单中密码部分  
<el-form-item prop="password">
            <div class="inputs">
              <label class="label1">
                <img src="../assets/icons/pass.png" class="icon_img" />
              </label>
              <input
                v-model="FormData.password"
                type="password"
                placeholder="请输入密码"
                show-password
                class="longin_inputs"
                v-if="ispwda"
              />
              <input
                v-model="FormData.password"
                type="text"
                placeholder="请输入密码"
                show-password
                class="longin_inputs"
                v-else
              />
              <span class="label2" @click="showPwd()">
                <img src="../assets/icons/pwda.png" class="icon_img" v-if="ispwda" />
                <img src="../assets/icons/pwds.png" class="icon_img" v-else />
              </span>
            </div>
          </el-form-item>

分别给被点击的图标和改变的input框绑定一个值,再判断即可。

 ispwda: true,
showPwd() {
      if (this.ispwda) {
        this.ispwda = false;
      } else {
        this.ispwda = true;
      }
    }

方法二:通过改变input框的type属性实现

 <el-form-item prop="newPwd">

                <input
                  v-model="ruleForm.newPwd"
                  :type="isPassword"
                  placeholder="输入新密码"
                  class="form-input"
                  clearable               
                />
                <span class="label2" @click="showPwd()">
                  <img src="../../assets/icons/hide2.png" class="icon_img" v-if="isnewPwd" />
                  <img src="../../assets/icons/show2.png" class="icon_img" v-else />
                </span>
            
          </el-form-item>
 return {
      isPassword:'password',
      isnewPwd:false
      
  },
  created() {},
  methods: {
showPwd() {
      if (this.isnewPwd) {
        this.isPassword='text';
        this.isnewPwd = false;
       
      } else {
        this.isPassword='password';
        this.isnewPwd = true;
        
      }
    }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值