Browse Source

fix(nc-gui): unbind events when elements are unmounted

pull/3801/head
braks 2 years ago
parent
commit
452263f8b5
  1. 9
      packages/nc-gui/plugins/resizeDirective.ts
  2. 4
      packages/nc-gui/plugins/tele.ts

9
packages/nc-gui/plugins/resizeDirective.ts

@ -38,6 +38,8 @@ export default defineNuxtPlugin((nuxtApp) => {
document.documentElement.addEventListener('mouseup', stopDrag, false)
}
;(el as any).initDrag = initDrag
let width: number | string
// emit event on dragging
@ -56,5 +58,12 @@ export default defineNuxtPlugin((nuxtApp) => {
emit('xcresized')
}
},
beforeUnmount: (el: Element) => {
const resizer = el.querySelector('.resizer')
if (resizer) {
resizer.removeEventListener('mousedown', (el as any).initDrag, false)
}
},
})
})

4
packages/nc-gui/plugins/tele.ts

@ -58,6 +58,10 @@ export default defineNuxtPlugin(async (nuxtApp) => {
if (vnode.el) vnode.el.addEventListener('click', getListener(binding))
else el.addEventListener('click', getListener(binding))
},
beforeUnmount(el, binding, vnode) {
if (vnode.el) vnode.el.removeEventListener('click', getListener(binding))
else el.removeEventListener('click', getListener(binding))
},
})
function getListener(binding: any) {

Loading…
Cancel
Save