项目场景:
uniapp 小程序在ios中验证码自动填充功能,在模拟器和体验版正常,但在上线后真机验证码会自动填充两次
问题描述
`在粘贴验证码的时候由于填充了两次导致验证码失效
解决方案:需监听验证码输入正确过后自动进行操作 监听第二次填充的时时间做防抖处理
export function debounce(fn, delay) {
let timer;
return function () {
const that = this;
const _args = arguments; // 存一下传入的参数
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(function () {
fn.apply(that, _args);
}, delay);
};
}
// 在 onChange 事件中传入两个参数
<Input
v-model="msg"
style="width: 100%"
@on-change="(e) => {onChange(e?.target?.value, item);}">
</Input>
使用 :
onChange: debounce(function (value, row) {
console.log('value',value);
},500),