Created
March 27, 2021 13:38
-
-
Save Tahul/89eb822333dfab232cf5dea76817a7c1 to your computer and use it in GitHub Desktop.
[Vue 2 & 3 Typed Directive] A typed directive compatible with both Vue 2 & 3 using vue-demi. #vue #vue2 #vue3 #directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, DirectiveBinding, VNode } from 'vue-demi' | |
export const directive = (): Directive<HTMLElement | SVGElement> => { | |
const register = ( | |
el: HTMLElement | SVGElement, | |
binding: DirectiveBinding, | |
node: VNode< | |
any, | |
HTMLElement | SVGElement, | |
{ | |
[key: string]: any | |
} | |
>, | |
) => {} | |
const unregister = ( | |
el: HTMLElement | SVGElement, | |
binding: DirectiveBinding, | |
node: VNode< | |
any, | |
HTMLElement | SVGElement, | |
{ | |
[key: string]: any | |
} | |
>, | |
) => {} | |
return { | |
// Vue 3 Directive Hooks | |
created: register, | |
unmounted: unregister, | |
// Vue 2 Directive Hooks | |
// @ts-expect-error | |
bind: register, | |
unbind: unregister, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment