vue判断input框获取焦点以及失去焦点,让input框自动获取焦点

<input type="text" @focus="searchfun" @blur="searchfun_close" ref="inputref">
//input失去焦点时执行的方法
searchfun_close(){
    this.searchpopupShow=false
},
//input当前获取焦点执行的方法
searchfun(){
    this.searchpopupShow=true
},

//让input框获取焦点
searchfuns(){
    this.$refs.inputref.focus()
}

@focus方法当获取焦点时执行

@blur方法当失去焦点时执行

通过ref让input框获取焦点

猜你喜欢

转载自blog.csdn.net/stars______/article/details/129859019