[bugfix] click outside mixin event binding (#3584)

This commit is contained in:
neverland 2019-06-21 14:37:11 +08:00 committed by GitHub
parent f86ab3a4d5
commit caa83ac4a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -1,3 +1,6 @@
/**
* Bind event when mounted or activated
*/
import { on, off } from '../utils/dom/event';
export function BindEventMixin(handler) {

View File

@ -1,17 +1,20 @@
/**
* Listen to click outside event
*/
import { on, off } from '../utils/dom/event';
export const ClickOutsideMixin = config => ({
mounted() {
config.handler = event => {
this.clickOutsideHandler = event => {
if (!this.$el.contains(event.target)) {
this[config.method]();
}
};
on(document, config.event, config.handler);
on(document, config.event, this.clickOutsideHandler);
},
beforeDestroy() {
off(document, config.event, config.handler);
off(document, config.event, this.clickOutsideHandler);
}
});