---
title: "vClickOutside"
description: "vClickOutside is a Vue directive to trigger a function when the user clicks outside an element"
package: "maz-ui"
url: "https://maz-ui.com/directives/click-outside"
---
# vClickOutside
> vClickOutside is a Vue directive to trigger a function when the user clicks outside an element
- Package: `maz-ui`
- Import: `import { vClickOutside } from 'maz-ui/directives/vClickOutside'`
- Web: https://maz-ui.com/directives/click-outside
## Basic usage
```vue
Click outside me
You clicked outside
```
## Advanced usage with options
The directive can accept an options object to customize its behavior:
```vue
Click outside me (but not on the button below)
This button is ignored
```
## Using the `once` option
The directive can be configured to trigger only once:
```vue
Click outside me (works only once)
```
## All options combined
Here's an example using all available options:
```vue
```
## API Reference
### Usage Patterns
```vue
...
...
```
### Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `callback` | `Function` | `undefined` | **Required.** Function to call when clicking outside |
| `ignore` | `string[]` | `[]` | Array of CSS selectors to ignore when detecting clicks |
| `capture` | `boolean` | `false` | Whether to use capture phase for event listening |
| `once` | `boolean` | `false` | Whether to trigger the callback only once |
### Type Definitions
```typescript
interface VClickOutsideOptions {
callback: (...args: any[]) => any
ignore?: string[]
capture?: boolean
once?: boolean
}
type vClickOutsideBindingValue =
| ((...args: any[]) => any)
| VClickOutsideOptions
```
## Global install
### Vue
```typescript
import { vClickOutsideInstall } from 'maz-ui/directives'
import { createApp } from 'vue'
const app = createApp(App)
app.use(vClickOutsideInstall)
app.mount('#app')
```
### Nuxt
Please refer to the [Nuxt module documentation](../ecosystem/nuxt.md) for more information.