An open API service indexing awesome lists of open source software.

https://github.com/idimetrix/vue2-click-outside

Vue 2 directive to react on clicks outside an element without stopping the event propagation
https://github.com/idimetrix/vue2-click-outside

Last synced: 6 months ago
JSON representation

Vue 2 directive to react on clicks outside an element without stopping the event propagation

Awesome Lists containing this project

README

        

# vue2-click-outside

Vue directive to react on clicks outside an element without stopping the event propagation.

## Install

```bash
$ npm install --save vue2-click-outside
```

```bash
$ yarn add vue2-click-outside
```

## Use

```js
import Vue from 'vue'
import Vue2ClickOutside from 'vue2-click-outside'

Vue.use(Vue2ClickOutside)
```

```js

export default {
data () {
clickOutsideConfig: {
handler: this.handler,
middleware: this.middleware,
events: ['dblclick', 'click'],
active: true
}
},
methods: {
onClickOutside (event, el) {
console.log('Clicked outside. Event: ', event)
},

handler (event, el) {
console.log('Clicked outside (Using config), middleware returned true :)')
},
middleware (event, el) {
return event.target.className !== 'modal'
}
}
};


```

Or use it as a directive

```js
import Vue2ClickOutside from 'vue2-click-outside'

export default {
directives: {
clickOutside: Vue2ClickOutside.directive
},
methods: {
onClickOutside (event) {
console.log('Clicked outside. Event: ', event)
}
}
};

```

## License

MIT