2

I'm currently working on a project which uses VueJS. This project has many mixins and components and in the HTML @click is defined on many places.

Is it possible to get a list of DOM nodes which has these event listers attached? Or extend the main event listener functionality so that i can add some extra logic to it? I've searched for the answer for hours but still not able to find anything useful.

Thanks!

6
  • 1
    It's not clear (to me at least) what exactly you want to do. Do you want to intercept every handler assigned by the v-on directive? Commented Jun 12, 2018 at 13:54
  • one possible approach is using vue directive, then loop vnode to check whehter any listener exists. Commented Jun 12, 2018 at 15:40
  • @Bert Yes that is exactly what i want to do. Commented Jun 13, 2018 at 6:25
  • @Sphinx I tried it with a vue directive but i still didn't get it to work. Commented Jun 13, 2018 at 6:25
  • 1
    Great, possible Vue Source Code may be helpful for further understanding. Commented Jun 13, 2018 at 15:52

1 Answer 1

1

I just wanted to let you know that after a lot of debugging i found a way to determine what elements have an @click event attached. For those who still want to know:

function loopThroughVueNodeChildren(children) {
    children.forEach(vnode => {
        // Is an @click attached to this element?
        if (vnode.data && typeof vnode.data.on !== 'undefined' && typeof vnode.data.on.click === 'function') {
            console.log('This element has an @click event! I can do whatever i need to do in here :)');
        }

        if (vnode.children) {
            this.addEventListenerOnVueNodes(vnode.children);
        }
    })
},


loopThroughVueNodeChildren(this._vnode.children);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.