chore: remove mixin extend

This commit is contained in:
chenjiahan
2020-07-01 17:12:50 +08:00
parent 02e288e3cb
commit 1b58e872fd
6 changed files with 55 additions and 97 deletions
+31
View File
@@ -0,0 +1,31 @@
/**
* Listen to click outside event
*/
import { on, off } from '../utils/dom/event';
export const ClickOutsideMixin = (config) => ({
props: {
closeOnClickOutside: {
type: Boolean,
default: true,
},
},
data() {
const clickOutsideHandler = (event) => {
if (this.closeOnClickOutside && !this.$el.contains(event.target)) {
this[config.method]();
}
};
return { clickOutsideHandler };
},
mounted() {
on(document, config.event, this.clickOutsideHandler);
},
beforeDestroy() {
off(document, config.event, this.clickOutsideHandler);
},
});