完美禁用el-input type为password自动填充密码功能
1.autoComplete='new-password'
2.autoComplete='off'
上述两种情况都无效
html部分代码
<el-form-item
:prop="'paramList.' + scope.$index + '.paramValue'"
:rules="paramsRules.paramValue"
>
<template v-if="scope.row.paramCode ==='password'">
<el-input
type="password"
:autoComplete="scope.row.paramCode === 'password'? 'new-password' : 'off'"
:value='scope.row.paramValue'
@input='pwdInput($event,scope.row)'
placeholder='请输入参数值'
:readonly="readonly" <!--默认是true--->
auto-complete="confirm-password"
@focus="changAttr($event,'focus')"
@blur="changAttr($event,'blur')"
@click.native="clickEvt"
ref="password"
>
</el-input>
</template>
<template v-else>
<el-input
v-model='scope.row.paramValue'
placeholder='请输入参数值'
>
</el-input>
</template>
</el-form-item>
js代码
methods: {
pwdInput(e,row) {
row.paramValue = e
if(!e) {
this.readonly = true
}
},
changAttr(e, type) {
if (type === 'focus') {
if (e) {
e.stopPropagation();
e.preventDefault();
console.log(e.target.value)
}
setTimeout(() => {
this.readonly = false;
}, 100);
} else {
if (e) {
e.stopPropagation();
}
this.readonly = true;
}
},
clickEvt() {
if (this.$refs.password) {
this.$refs.password.$refs.input.onmousedown = (evt) => {
if (evt) {
evt.preventDefault();
evt.stopPropagation();
}
console.log(this.$refs.password.$refs.input.value)
if (this.$refs.password.$refs.input.value ==='' || this.readonly) {
this.$refs.password.$refs.input.blur();
setTimeout(() => {
this.$refs.password.$refs.input.focus();
}, 0);
}
return false;
};
}
},
}
代码搬运工

浙公网安备 33010602011771号