Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a global config to show event handlers during development #7532

Closed
smalllong opened this issue Jan 25, 2018 · 5 comments
Closed

Add a global config to show event handlers during development #7532

smalllong opened this issue Jan 25, 2018 · 5 comments

Comments

@smalllong
Copy link

smalllong commented Jan 25, 2018

What problem does this feature solve?

During development, it's hard to find out what method is used to handle events on the element using browser's DOM inspector. If it's able to see the handler's name or content during development, it will be easier for the developer to locate the handler's code.

What does the proposed API look like?

Set global config:

Vue.config.showHandlers = true;

then the handlers can be seen in the DOM inspector:

<div v-on:click='showHahaha' v-on:mouseenter='active = true'>hahaha</div>

since '@' is not valid in Element.setAttribute, I changed it to 'v-on:'

@posva
Copy link
Member

posva commented Jan 25, 2018

Related answer: #2415 (comment)

Personally, I think to add this only in development would potentially create other problems that would make debugging harder. It's also necessary to keep them in sync while updating the HTML which would take quite some effort for questionable gain.

Are you aware of vue devtools? They make Vue apps debugging much easier

@smalllong
Copy link
Author

smalllong commented Jan 26, 2018

@posva Actually, it's quite easy to add this feature, and I'm already using it during development. In function _createElement:
if (process.env.NODE_ENV !== 'production' && isDef(data) && isDef(data.on)) { data.attrs = data.attrs || {}; for (var i in data.on) { data.attrs['v-on:'+i] = data.on[i]._name } }
and in function bind:
boundFn._name = fn.name

@soanvig
Copy link

soanvig commented Feb 20, 2018

I see no point in implementing such a thing. Why?

  1. There are dedicated devtools.
  2. Because unit tests it is useless too: one should be testing if everything is executed as it should anyway.

@yyx990803
Copy link
Member

This is not something that should be done by Vue. Chrome already gives you the ability to inspect listeners on arbitrary DOM elements.

@smalllong
Copy link
Author

@yyx990803 However, I think the Chrome inspector's listeners shown in Vue apps are not readable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants