C
C
crdrads2019-03-14 18:31:57
Vue.js
crdrads, 2019-03-14 18:31:57

How to remove Event Listener in custom directive?

The directive in inserted has this

function myFunc () { console.log('RESIZE!!!') }
window.addEventListener('resize', myFunc)

The listener stays hung even when moving to another page where this directive is not used. Can't figure out how to remove it? In unbind, I cannot use the function because it uses the variables from inserted

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2019-03-14
@Fragster

A mixin is more suitable here, rather than a directive. In it, you can register your reaction to mounted and beforeDestroy

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question