关于elementui和ant design vue无法禁止浏览器自动填充问题

以and design vue 为例:

图标用来显隐账号密码

html:

 <a-form-model-item label="账号密码:" prop="password">
                  <a-input v-if="passwordTab" ref="passwordInput" v-model="form.password" type="text" style="width: 280px" @input="inputPassword">
                    <template #suffix>
                      <svg-icon v-if="!passwordTab" class="icons-dg" style="color: rgba(0, 0, 0, 0.65)" iconClass="dg-nosee" @click="changeVent('passwordTab',true)" />
                      <i v-else class="el-icon-view icons-dg" @click="changeVent('passwordTab',false)" />
                    </template>
                  </a-input>
                  <a-input v-else ref="passwordInput" v-model="password" type="text" style="width: 280px" @input="inputPassword">
                    <template #suffix>
                      <svg-icon v-if="!passwordTab" class="icons-dg" style="color: rgba(0, 0, 0, 0.65)" iconClass="dg-nosee" @click="changeVent('passwordTab',true)" />
                      <i v-else class="el-icon-view icons-dg" @click="changeVent('passwordTab',false)" />
                    </template>
                  </a-input>
                </a-form-model-item>

js:

会生成*号字符串并把原值v-model赋值给form.password表单。自行修改,我这边的表单结构是:

form:{ password,...[more]}

    inputPassword(e) {
      const value = e.target.value // 当前的值
      const oldVal = this.form.password // 之前的值
      let passwordShow = '' // 当前输入下需要显示的值,及n个*的字符串
      let text = '' // 当前input事件输入的值,如果是删除就没有值
      // 当前input指针的位置,不一定是在最后
      const startPoint = e.target.selectionStart
      const endPoint = e.target.selectionEnd
      if (!value) {
        this.form.password = ''
        this.password = ''
        return
      }
      let leftNum = 0 // 输入后左边保留多少
      let rightNum = 0 // 输入后右边保留多少
      let isLeft = true
      for (let i = 0; i < value.length; i++) {
        passwordShow += '*'
        if (value[i] == '*') {
          if (isLeft) {
            leftNum++
          } else {
            rightNum++
          }
          continue
        }
        text += value[i]
        isLeft = false
      }

      if (text) {
        this.form.password =
          oldVal.slice(0, leftNum) +
          text +
          oldVal.slice(oldVal.length - rightNum)
      } else {
        this.form.password =
          oldVal.slice(0, startPoint) +
          oldVal.slice(oldVal.length - leftNum - rightNum + startPoint)
      }
      this.password = passwordShow
      this.$nextTick(() => {
        e.target.setSelectionRange(startPoint, startPoint)
      })
    },

 这个是把显示隐藏账号密码做个false和true处理

 changeVent(type, val) {
      this[type] = val
    },

data对象:

data(){
    return{
      passwordTab: false,
      password: '',
      form:{
      password:''
}
}
}

 效果:

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值