我是用vant的组件van-field
<van-field
v-model="driveRegisterInfo.driverLicenseName"
placeholder="请输入驾驶证姓名"
type="text"
label="驾驶证姓名"
required
@focus="focusDriverLicenseName"
@blur="blurDriverLicenseName"
>
<template v-slot:right-icon>
<van-icon
name="clear"
@click="clearDriverLicenseName"
style="font-size: 0.3rem"
color="#989DB2"
/>
</template>
</van-field>
//驾驶证姓名获取焦点
在methods中写方法
focusDriverLicenseName() {
window.addEventListener("resize", function () {
if (
document.activeElement.tagName === "INPUT" ||
document.activeElement.tagName === "TEXTAREA"
) {
interval = window.setTimeout(function () {
if ("scrollIntoView" in document.activeElement) {
document.activeElement.scrollIntoView();
} else {
document.activeElement.scrollIntoViewIfNeeded();
}
}, 0);
}
});
},
//驾驶证姓名失去焦点
blurDriverLicenseName() {
clearInterval(interval);
},