vuejs-challenges
vuejs-challenges copied to clipboard
19 - 切换焦点指令
// 你的答案
<script setup lang='ts'>
import { ref } from "vue"
const state = ref(false)
/**
* Implement the custom directive
* Make sure the input element focuses/blurs when the 'state' is toggled
*
*/
const VFocus = {
mounted: (el) => el.focus()
}
setInterval(() => {
state.value = !state.value
}, 2000)
</script>
<template>
<input v-focus="state" type="text">
</template>