🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## useFocus ``` const target = ref() const { focused } = useFocus(target) watch(focused, (focused) => { if (focused) console.log('input element has been focused') else console.log('input element has lost focus') }) ``` 初始激活值 ``` import { useFocus } from '@vueuse/core' const target = ref() const { focused } = useFocus(target, { initialValue: true }) ``` ## useFocusWithin 指定元素没有被激活 ``` import { useFocusWithin } from '@vueuse/core' const target = ref(); const { focused } = useFocusWithin(target) watch(focused, focused => { if (focused) console.log('Target contains the focused element') else console.log('Target does NOT contain the focused element') }) ```