Vue3+Element Plus,el-input自动聚焦
<el-input />
外层嵌套了div
,导致官方提供的autofocus属性失效。所以使用调用focus函数。
实现方法
<el-input ref="inputRef" v-model="inputContent" clearable />
定义一个函数focusInput
,并触发就可以
const focusInput = () => { nextTick(() => { inputRef.value.focus() }) }
Tips:
写在setTimeout函数或者onMounted()函数里都不生效。focusInput
需要不断的被调用才行。