web端 取消 input 输入框 自动回填数据的问题

154 阅读1分钟

有时候我们使用input框的时候不想让其自动填充内容

一般来说有一个简便方法和一个复杂方法

简便方法:设置属性值

  • autocomplete="off"
  • autocomplete="new-password"

当简便方法无效时,使用复杂方法

<el-input
placeholder="请输入验证码"
v-model="forgetForm.code"
:readonly="isReadonly"
@focus="changeReadonly"
ref="captchaInput"
></el-input>

isReadonly: true, // 是否只读 解决获取验证码的输入框总是自动填充的问题

changeReadonly() {
    this.isReadonly = false;
    this.$nextTick(() => {
      this.$refs.captchaInput.focus();
    });
},