mirror of https://github.com/ElemeFE/element
clickoutside: fix memory leak
parent
ed511e9219
commit
d419e260d0
|
@ -12,20 +12,11 @@ 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));
|
||||||
});
|
});
|
||||||
/**
|
|
||||||
* v-clickoutside
|
function createDocumentHandler(el, binding, vnode) {
|
||||||
* @desc 点击元素外面才会触发的事件
|
return function(mouseup = {}, mousedown = {}) {
|
||||||
* @example
|
if (!vnode ||
|
||||||
* ```vue
|
!vnode.context ||
|
||||||
* <div v-element-clickoutside="handleClose">
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
export default {
|
|
||||||
bind(el, binding, vnode) {
|
|
||||||
nodeList.push(el);
|
|
||||||
const id = seed++;
|
|
||||||
const documentHandler = function(mouseup = {}, mousedown = {}) {
|
|
||||||
if (!vnode.context ||
|
|
||||||
!mouseup.target ||
|
!mouseup.target ||
|
||||||
!mousedown.target ||
|
!mousedown.target ||
|
||||||
el.contains(mouseup.target) ||
|
el.contains(mouseup.target) ||
|
||||||
|
@ -43,15 +34,30 @@ export default {
|
||||||
el[ctx].bindingFn && el[ctx].bindingFn();
|
el[ctx].bindingFn && el[ctx].bindingFn();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* v-clickoutside
|
||||||
|
* @desc 点击元素外面才会触发的事件
|
||||||
|
* @example
|
||||||
|
* ```vue
|
||||||
|
* <div v-element-clickoutside="handleClose">
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
bind(el, binding, vnode) {
|
||||||
|
nodeList.push(el);
|
||||||
|
const id = seed++;
|
||||||
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