mirror of https://github.com/ElemeFE/element
clickoutside: fix memory leak
parent
ed511e9219
commit
d419e260d0
|
@ -12,6 +12,30 @@ let seed = 0;
|
||||||
!Vue.prototype.$isServer && on(document, 'mouseup', e => {
|
!Vue.prototype.$isServer && on(document, 'mouseup', e => {
|
||||||
nodeList.forEach(node => node[ctx].documentHandler(e, startClick));
|
nodeList.forEach(node => node[ctx].documentHandler(e, startClick));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function createDocumentHandler(el, binding, vnode) {
|
||||||
|
return function(mouseup = {}, mousedown = {}) {
|
||||||
|
if (!vnode ||
|
||||||
|
!vnode.context ||
|
||||||
|
!mouseup.target ||
|
||||||
|
!mousedown.target ||
|
||||||
|
el.contains(mouseup.target) ||
|
||||||
|
el.contains(mousedown.target) ||
|
||||||
|
el === mouseup.target ||
|
||||||
|
(vnode.context.popperElm &&
|
||||||
|
(vnode.context.popperElm.contains(mouseup.target) ||
|
||||||
|
vnode.context.popperElm.contains(mousedown.target)))) return;
|
||||||
|
|
||||||
|
if (binding.expression &&
|
||||||
|
el[ctx].methodName &&
|
||||||
|
vnode.context[el[ctx].methodName]) {
|
||||||
|
vnode.context[el[ctx].methodName]();
|
||||||
|
} else {
|
||||||
|
el[ctx].bindingFn && el[ctx].bindingFn();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* v-clickoutside
|
* v-clickoutside
|
||||||
* @desc 点击元素外面才会触发的事件
|
* @desc 点击元素外面才会触发的事件
|
||||||
|
@ -24,34 +48,16 @@ export default {
|
||||||
bind(el, binding, vnode) {
|
bind(el, binding, vnode) {
|
||||||
nodeList.push(el);
|
nodeList.push(el);
|
||||||
const id = seed++;
|
const id = seed++;
|
||||||
const documentHandler = function(mouseup = {}, mousedown = {}) {
|
|
||||||
if (!vnode.context ||
|
|
||||||
!mouseup.target ||
|
|
||||||
!mousedown.target ||
|
|
||||||
el.contains(mouseup.target) ||
|
|
||||||
el.contains(mousedown.target) ||
|
|
||||||
el === mouseup.target ||
|
|
||||||
(vnode.context.popperElm &&
|
|
||||||
(vnode.context.popperElm.contains(mouseup.target) ||
|
|
||||||
vnode.context.popperElm.contains(mousedown.target)))) return;
|
|
||||||
|
|
||||||
if (binding.expression &&
|
|
||||||
el[ctx].methodName &&
|
|
||||||
vnode.context[el[ctx].methodName]) {
|
|
||||||
vnode.context[el[ctx].methodName]();
|
|
||||||
} else {
|
|
||||||
el[ctx].bindingFn && el[ctx].bindingFn();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
el[ctx] = {
|
el[ctx] = {
|
||||||
id,
|
id,
|
||||||
documentHandler,
|
documentHandler: createDocumentHandler(el, binding, vnode),
|
||||||
methodName: binding.expression,
|
methodName: binding.expression,
|
||||||
bindingFn: binding.value
|
bindingFn: binding.value
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
update(el, binding) {
|
update(el, binding, vnode) {
|
||||||
|
el[ctx].documentHandler = createDocumentHandler(el, binding, vnode);
|
||||||
el[ctx].methodName = binding.expression;
|
el[ctx].methodName = binding.expression;
|
||||||
el[ctx].bindingFn = binding.value;
|
el[ctx].bindingFn = binding.value;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue