1. Input 属性增加autofocus
<el-input
v-model="scanner.workds"
type="textarea"
ref="scannerArea"
placeholder="Scanner Working"
clearable
:autosize="{ minRows: 3 }"
autofocus
/>
- ts 通过onMounted操控ref 前端input
const scannerArea = ref<HTMLInputElement | HTMLTextAreaElement | null>(null)
onMounted(() => {
if (scannerArea.value) {
scannerArea.value.focus()
}
})