多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[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') }) ```