ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[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') }) ```