解决 el-input 密码输入框浏览器自动填充账号密码问题

  通常情况下,浏览器会默认将已保存的账号密码 填充到 input    type 值为password的输入框内,如果在登录页面,这当然是非常好的,自动填充密码可以节约时间,提高良好的使用体验,这样当然是没有什么问题的

但是如果在注册页面、新增账号等页面,这种操作 就是超出需求了(有点多此一举)
 

     <el-col :span="12">
          <el-form-item label="邮箱:" prop="email"
            ><el-input  v-model="ruleForm.email"></el-input
          ></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="密码:" prop="password"
            ><el-input  type="password" v-model="ruleForm.password"></el-input
          ></el-form-item>
        </el-col>

 解决方法

auto-complete="new-password"

 在 type 为 passworld 的 input 中加 auto-complete="new-password" 属性即可

   <el-col :span="12">
          <el-form-item label="邮箱:" prop="email"
            ><el-input auto-complete="new-password" v-model="ruleForm.email"></el-input
          ></el-form-item>
        </el-col>
    
        <el-col :span="12">
          <el-form-item label="密码:" prop="password"
            ><el-input auto-complete="new-password" type="password" v-model="ruleForm.password"></el-input
          ></el-form-item>
        </el-col>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在使用Vue框架的el-input组件时,浏览器自动填充可能会造成一些问题浏览器自动填充浏览器根据用户之前的输入记录和记住密码等信息自动填充输入框内容的功能。但是这个功能也许不符合我们的需求,所以需要解决这个问题解决浏览器自动填充的方法有以下几种: 1. 屏蔽自动填充:可以通过设置input标签的autocomplete属性为off来禁止自动填充。 ```html <el-input v-model="inputValue" :autocomplete="'off'" ></el-input> ``` 2. 修改input事件:通过监听input事件,手动更新数据模型中的值,这样可以覆盖浏览器自动填充的内容。 ```html <el-input v-model="inputValue" @input="handleInput" ></el-input> ``` ```javascript methods: { handleInput() { this.inputValue = this.$refs.input.value; // 获取input框的值并更新数据模型 }, }, ``` 3. 利用setTimeout延迟设置值:使用setTimeout可以使得设置值操作在下一次事件循环开始,从而避免被浏览器自动填充的值覆盖。 ```javascript mounted() { setTimeout(() => { this.inputValue = ''; }, 0); }, ``` 4. 结合JavaScript和Vue的解决方案:在mounted钩子函数中使用JavaScript的代码将input框的值清空,并将其焦点移至其他input元素。 ```javascript mounted() { let input = document.getElementById('inputId'); input.value = ''; let otherInput = document.getElementById('otherInputId'); otherInput.focus(); }, ``` 这些方法可以有效解决浏览器自动填充所带来的问题,根据需要选择适合的解决方案即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值