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 => {
|
||||
nodeList.forEach(node => node[ctx].documentHandler(e, startClick));
|
||||
});
|
||||
/**
|
||||
* v-clickoutside
|
||||
* @desc 点击元素外面才会触发的事件
|
||||
* @example
|
||||
* ```vue
|
||||
* <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 ||
|
||||
|
||||
function createDocumentHandler(el, binding, vnode) {
|
||||
return function(mouseup = {}, mousedown = {}) {
|
||||
if (!vnode ||
|
||||
!vnode.context ||
|
||||
!mouseup.target ||
|
||||
!mousedown.target ||
|
||||
el.contains(mouseup.target) ||
|
||||
|
@ -43,15 +34,30 @@ export default {
|
|||
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] = {
|
||||
id,
|
||||
documentHandler,
|
||||
documentHandler: createDocumentHandler(el, binding, vnode),
|
||||
methodName: binding.expression,
|
||||
bindingFn: binding.value
|
||||
};
|
||||
},
|
||||
|
||||
update(el, binding) {
|
||||
update(el, binding, vnode) {
|
||||
el[ctx].documentHandler = createDocumentHandler(el, binding, vnode);
|
||||
el[ctx].methodName = binding.expression;
|
||||
el[ctx].bindingFn = binding.value;
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue