【setup】vue3+ts默认获取焦点,默认选中内容

164 阅读1分钟

<script setup lang='ts'>
import { nextTick } from 'vue';

const vFocus = {
    beforeMount: (el: HTMLInputElement) => {
        nextTick(() => el.focus());
    }
}

const vSelect = {
    beforeMount: (el: HTMLInputElement) => {
        nextTick(() => {
            el.select()
        });
    }
}

</script>

<template>
    <input type="text" :value="'默认获取焦点'" v-focus>
    <input type="text" :value="'默认选中'" v-select>
</template>

<style scoped>
</style>