Skip to content

Feature: reverse lookup element to vm #105

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

Closed
simplesmiler opened this issue May 26, 2016 · 6 comments
Closed

Feature: reverse lookup element to vm #105

simplesmiler opened this issue May 26, 2016 · 6 comments

Comments

@simplesmiler
Copy link
Member

It's possible to "Inspect DOM" for given vm, and Chrome will open "Elements" panel and select the root element of vm.

It would be helpful, if there was a way to do the reverse of that. Given the element, open "Vue Devtools" panel and select the vm this element is governed by (if any).

@simplesmiler
Copy link
Member Author

simplesmiler commented May 27, 2016

Might be slightly complicated for slots, because for slots the closest element with viewmodel bound to it is not the viewmodel the data comes from.

var Home = {
  template: `
    <div>
      <tab-group>
        <tab-page v-for="tab in tabs">
          <div>{{ <belongs to "home" vm, not to "tab-page" vm> }}</div>
        </tab-page>
      </tab-group>
    </div>
  `,
};

@blake-newman
Copy link
Member

@simplesmiler Any luck with this... I don't see that there is many other tools with this capability.

@simplesmiler
Copy link
Member Author

simplesmiler commented Jul 25, 2016

I think the best way to do that would be to inject a vm reference into every element this vm governs. It's already done with root elements (element.__vue__).

Don't have time to try to implement it yet.


UPDATE: Should not inject __vue__ into every element, because it would break the logic elsewhere. Better choose a different name. And only inject when Vue.config.devtools === true.

@simplesmiler
Copy link
Member Author

simplesmiler commented Jul 29, 2016

Another complication is that in Vue 2 element may belong to multiple instances. The example below is producing a fragment (elementless) instance in Vue 1, but in Vue 2 it is absolutely valid. The __vue__ seems to point at the parent instance.

Example: https://jsfiddle.net/simplesmiler/5LydL0hz/

I see two options:

  • Show user a list of instances this element belongs to.
  • Always pick the first (or last) instance from the list.

@michalsnik
Copy link
Member

I'm not sure it's worth the hassle actually. I don't see any interest around this functionality since it was proposed, so I'm going to close it now, and we'll rather focus on more vital things :)

@Akryum
Copy link
Member

Akryum commented Jan 4, 2018

If I understand OP correctly, it is implemented by #476 and #479.

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

No branches or pull requests

4 participants