Revert "chore: remove hooks ooops!"

This reverts commit 8d4d965a85.
This commit is contained in:
陈嘉涵
2020-01-14 17:20:15 +08:00
parent 28da4dce0c
commit 2e6dbca06d
4 changed files with 185 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
import { Ref } from 'vue';
import { useGlobalEvent } from './use-global-event';
export type UseClickOutsideOpitons = {
event: string;
callback: EventListener;
element: Ref<Element>;
flag?: Ref<boolean>;
};
export function useClickOutside(options: UseClickOutsideOpitons) {
const { event = 'click', callback, element, flag } = options;
function onClick(event: Event) {
if (!element.value.contains(event.target as Node)) {
callback(event);
}
}
useGlobalEvent(document, event, onClick, false, flag);
}