完美解决:antd-vue Chrome禁用账号密码自动填充

背景:在系统登录页中,点击chrome中的默认保存会自动填充账号密码,现在想把这个默认功能去掉。。。

网上看到了:都是用autocomplete="off" autocomplete="new-password"就能使用了,我就高兴的copy,见鬼的是大家都说能用,只有我不行。。。,注意了下,文章的日期,大多是几年前的。。一个大胆的想法产生了,就是高版本浏览器无法支持autocomplete,一番查看果然有人是这么回答的,

解决方式:

先让input 为readonly,得到焦点时候再把readonly去掉

antd-vue组件中

 <a-input-password
     size="large"
     type="password"
     readOnly
     placeholder="请输入密码"
     onfocus="this.removeAttribute('readonly');"                 
     onblur="this.setAttribute('readonly',true);"
     v-decorator="[ 'password', { rules: [{ required: true, message: '请输入密码' }],validateTrigger: 'blur' },]" />

input 组件

<input readOnly onfocus="this.removeAttribute('readonly');" onblur="this.setAttribute('readonly',true);" />

猜你喜欢

转载自blog.csdn.net/web_ding/article/details/122680885