我有以下代码来侦听和删除事件。但是,该事件不会被删除:
window.addEventListener('mousemove', (event) => {
this.controlColumnWidth(event, startOffset, column)
})
window.removeEventListener('mouseup', this.controlColumnWidth)
我该如何解决?
答案 0 :(得分:3)
您在这里混合了两个不同的事件,mousemove
和mouseup
。
还需要确保删除与最初注册的相同的(event) => { ... }
函数实例:
const handler = event => {
this.controlColumnWidth(event, startOffset, column);
};
window.addEventListener('mousemove', handler);
window.removeEventListener('mousemove', handler);
// You can also store the handler on `this` if you need to remove
// the event in a different function (such as in the destroyed hook)