uniapp中input框使用ref.focus()无法直接获取到焦点,需要先在input失去焦点时,将:focus的值改为false,然后通过setTimeout或$nextTick使input获取焦点
<template>
<input :focus='focusState' @blur='focusState = false' />
</template>
<script>
export default {
data (){
return {
focusState = true;
}
},
methods:{
clickFocus(){
this.$nextTick(() => {
this.focusState = true
})
}
}
}
</script>