需求:如图,需要在点开el-popover的时候自动聚焦到输入框中。
对于input获取焦点,element官网:
方法:el-input上绑定ref ,但是和el-popover联动,必须在el-popover的show上绑定
<el-popover @show="handleFocus" placement="bottom" width="300" v-model="visiblePerson" trigger="click" >
<el-input ref="inputFocus" v-model="personKeyWord" @input="remotePerson(personKeyWord, personList, personOption)" placeholder="输入关键字查询" prefix-icon="el-icon-search" ></el-input>
</el-popover>
handleFocus() {
this.$nextTick((_) => {
this.$refs.inputFocus&&this.$refs.inputFocus.focus();
})
},
最开始我监控el-popover的值为true,不行,还是得绑定在show的方法里。