```
```ts
const vDemo = (el: HTMLElement, binding: DirectiveBinding<{ color: string; text: string }>) => {
console.log(binding.value.color) // 'white'
console.log(binding.value.text) // 'hello'
}
```
## Dynamic Arguments
```vue-html
```
## Practical Examples
### v-click-outside
```ts
const vClickOutside = {
mounted(el: HTMLElement, binding: DirectiveBinding<() => void>) {
el._clickOutside = (event: MouseEvent) => {
if (!el.contains(event.target as Node)) {
binding.value()
}
}
document.addEventListener('click', el._clickOutside)
},
unmounted(el: HTMLElement) {
document.removeEventListener('click', el._clickOutside)
}
}
```
### v-tooltip
```ts
const vTooltip = {
mounted(el: HTMLElement, binding: DirectiveBinding) {
el.setAttribute('title', binding.value)
},
updated(el: HTMLElement, binding: DirectiveBinding) {
el.setAttribute('title', binding.value)
}
}
```
### v-permission
```ts
const vPermission = {
mounted(el: HTMLElement, binding: DirectiveBinding) {
if (!hasPermission(binding.value)) {
el.parentNode?.removeChild(el)
}
}
}
```
## TypeScript: Global Directives
```ts
// directives/highlight.ts
import type { Directive } from 'vue'
export type HighlightDirective = Directive
declare module 'vue' {
export interface ComponentCustomProperties {
vHighlight: HighlightDirective
}
}
export default {
mounted: (el, binding) => {
el.style.backgroundColor = binding.value
}
} satisfies HighlightDirective
```
## Usage on Components
⚠️ **Not recommended** - directives apply to root element, which can be unpredictable with multi-root components.
```vue-html
```