In Vue3 Type Declaration, there is a definition for the Directive
, which looks like this:
export declare type Directive<T = any, V = any> = ObjectDirective<T, V> | FunctionDirective<T, V>;
Most people are familiar with the ObjectDirective
:
export declare interface ObjectDirective<T = any, V = any> {
created?: DirectiveHook<T, null, V>;
beforeMount?: DirectiveHook<T, null, V>;
mounted?: DirectiveHook<T, null, V>;
beforeUpdate?: DirectiveHook<T, VNode<any, T>, V>;
updated?: DirectiveHook<T, VNode<any, T>, V>;
beforeUnmount?: DirectiveHook<T, null, V>;
unmounted?: DirectiveHook<T, null, V>;
getSSRProps?: SSRDirectiveHook;
deep?: boolean;
}
But what exactly is the FunctionDirective
?
export declare type FunctionDirective<T = any, V = any> = DirectiveHook<T, any, V>;
export declare type DirectiveHook<T = any, Prev = VNode<any, T> | null, V = any> = (el: T, binding: DirectiveBinding<V>, vnode: VNode<any, T>, prevVNode: Prev) => void;
I have searched through the official documentation but couldn't find much information about it. Can anyone explain what this is and how to use it?