123456789101112131415161718192021222324252627282930313233 |
- /**
- * Listen to click outside event
- */
- import { on, off } from '../utils/dom/event';
- export var ClickOutsideMixin = function ClickOutsideMixin(config) {
- return {
- props: {
- closeOnClickOutside: {
- type: Boolean,
- default: true
- }
- },
- data: function data() {
- var _this = this;
- var clickOutsideHandler = function clickOutsideHandler(event) {
- if (_this.closeOnClickOutside && !_this.$el.contains(event.target)) {
- _this[config.method]();
- }
- };
- return {
- clickOutsideHandler: clickOutsideHandler
- };
- },
- mounted: function mounted() {
- on(document, config.event, this.clickOutsideHandler);
- },
- beforeDestroy: function beforeDestroy() {
- off(document, config.event, this.clickOutsideHandler);
- }
- };
- };
|