[Vuejs]-Vue jquery within component

1👍

First I would recommend to not use jQuery together with Vue! As you already said, Vue is a framework which can manipulate the DOM without needing jQuery’s help.

But anyways, a quick ‘vue way’ solution is to use the beforeDestory hook on your login component, and clear your jQuery events.

beforeDestroy() {
  // Clean the listeners.
}

P.S. For next time, would be better to show some code 🙂

1👍

If I understand your problem correctly, you need to check to see if your handler exists already before setting it. That way if it already exists you won’t add it again.

In mounted() check if typeof window.onclick == 'object' if it does, then you haven’t set it yet and you can set your handler window.onclick = function() {}

If it is set then typeof window.onclick would equal 'function'

Leave a comment