<script setup lang="ts">
import { ref } from 'vue'
const inputEl = ref<HTMLInputElement>()
interface ExposedMethods {
inputEl: HTMLInputElement
focus: () => void
blur: () => void
select: () => void
getValue: () => string
setValue: (value: string) => void
}
defineExpose<ExposedMethods>({
inputEl: inputEl.value!,
focus: () => inputEl.value?.focus(),
blur: () => inputEl.value?.blur(),
select: () => inputEl.value?.select(),
getValue: () => inputEl.value?.value || '',
setValue: (value: string) => {
if (inputEl.value) {
inputEl.value.value = value
}
}
})
script>
<template>
<input type="text" ref="inputEl">
template>