mirror of
https://github.com/youzan/vant.git
synced 2025-10-18 09:24:25 +00:00
[bugfix] click outside mixin event binding (#3584)
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
/**
|
||||
* Bind event when mounted or activated
|
||||
*/
|
||||
import { on, off } from '../utils/dom/event';
|
||||
|
||||
export function BindEventMixin(handler) {
|
||||
|
@@ -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);
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user