会vue2的不会vue3,上次查找之后,记录一下,
<template>
<input
v-focus
type="text"
/>
</template>
<script setUp>
const vFocus = {
//必须以 vNameOfDirective 的形式来命名本地自定义指令,以使得它们可以直接在模板中使用。
beforeMount: (el) => {
// 在元素上做些操作
nextTick(() => {
el.focus() //获取焦点
})
}
}
</script>