<input type="text" v-model="tel" @focus="inputFocus($event)" @focusout="inputFocusout"/>
export default{
data(){
return {
timer:null,
}
},
methods: {
inputFocus(){
clearTimeout(this.timer)
},
inputFocusout() {
this.timer = setTimeout(() => {
window.scrollTo(0,0)
// 间隔设为10,减少页面失去焦点定时器的突兀感,
},10)
}
},
// 用户离开,就只执行销毁监听事件
destroyed() {
clearTimeout(this.timer)
}
}
网友评论