input父级绑定focusout事件
<template>
<div @focusout="inputBlur($event)" class="input-parent">
<input @focus="getFocus" placehoder="输入账号" />
<input @focus="getFocus" placehoder="输入密码" />
</div>
</template>
<script>
// other code
// input聚焦的时候记录 body的scrollTop
private getFocus(){
this.scrollTop = '" "
}
// 失去焦点之后键盘收起强制进行body归位
private inputBlur(e:any){
if (e && e.target && e.target.tagName && e.target.tagName.toLowerCase() === 'input') {
setTimeout(() => {
document.body.scrollTop = this.scrollTop;
}, 200);
}
}
</script>
网友评论