Skip to content

19 - 切换焦点指令 #2039

Open
Open
@kid1110

Description

@kid1110
// 你的答案
<script setup lang='ts'>
import { BindingTypes } from "@vue/compiler-core";
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 = {
  updated: (el, binding)=> binding.value ? el.focus():el.blur()
}

setInterval(() => {
  state.value = !state.value
}, 2000)

</script>

<template>
  <input v-focus="state" type="text">
</template>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions