vue 原生input 密码显示与隐藏

思路:通过点击事件来切换 input的类型(password 和 type)

          通过图片的动态渲染来决定显示与隐藏

1、html

  <div  style="width: 396px; font-size: 20px; color: #3d3d3d; float: left; margin-top: 21px; text-align:left">
            密码
          </div>
          <input :type="passwordType" v-model="password" placeholder="请输入密码"  maxlength="8" style=" display:inline; width: 396px; height: 30px; border-radius: 4px; opacity: 1; box-sizing: border-box;  border: 1px solid #d9d9d9; margin-top: 7px;" />
          <img :src="status" alt="" style="vertical-align:middle" @click="changeStatus()"> 
        </div>

2、js

  data () {
    return {
      status: require('../../assets/close.png'),
      passwordType: 'password',
      password: '',
      username: ''
    }
  },
methods:{
      // 密码切换
  changeStatus () {
      this.passwordType = this.passwordType === 'password' ? 'text' : 'password';
      this.status = this.status == require('../../assets/close.png') ? 
   require('../../assets/open.png') : require('../../assets/close.png')
    },
}

注意: 图片的引入一定要用 require 不然显示不出来!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值