<script> import { onMounted, ref } from "vue"; export default { setup() { const txtInput = ref(null); onMounted(() => { txtInput.value.focus(); }); const num = ref(12345); return { txtInput, num }; }, }; </script> <template> <input v-model="num" ref="txtInput" type="text" /> </template> <style> </style>
const txtInput = ref(null)
ref="txtInput"
txtInput.value.focus();
完整範例:
進階搜尋