Skip to content

Instantly share code, notes, and snippets.

@Tahul
Created March 27, 2021 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tahul/89eb822333dfab232cf5dea76817a7c1 to your computer and use it in GitHub Desktop.
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
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