Here's a simple options object for a directive. When the directive is destroyed what happens to the event listener? Is it stuck in memory or is it removed?
export default {
inserted (el) {
el.addEventListener('click', function () {
console.log('Click!')
})
}
}
No, that's your responsibility, in the unbind hook
function listener () {
console.log('Click!')
}
export default {
inserted (el) {
el.addEventListener('click', listener)
},
unbind(el) {
el.removeEventListener('click', listener)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With