Skip to content

Inspect $refs #450

New issue

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

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

Already on GitHub? # to your account

Closed
Christilut opened this issue Nov 9, 2017 · 13 comments
Closed

Inspect $refs #450

Christilut opened this issue Nov 9, 2017 · 13 comments

Comments

@Christilut
Copy link

It would be nice to be able to inspect this.$refs

Just like there is $route in a component, maybe it could have $refs below it?

@posva
Copy link
Member

posva commented Nov 9, 2017

can you elaborate a bit on why it would be nice?

@Christilut
Copy link
Author

Sometimes I need to see is inside a certain ref. Sometimes a ref is undefined and I want to know what refs a component has and confirm that it is actually undefined or that it was due to the component lifecycle.

Being able to see the $el inside a ref can help debugging as well.

@posva
Copy link
Member

posva commented Nov 9, 2017

Personally, I think it could be useful to highlight content as you hover them (pretty much like in the components panel) because you sometimes need to locate refs in the page and, as you said, know if they exist (undefined or not)

@Christilut
Copy link
Author

Yea, the ability to go from the vue devtools page to the Elements page would be really cool.
So for example, I click on a ref called video, it would go to the Elements tab (in Chrome dev tools) and highlight that video element.

@bartlomieju
Copy link
Contributor

I think I could implement it over the weekend, let me try and get a PR going.

@bartlomieju
Copy link
Contributor

bartlomieju commented Nov 25, 2017

I've sat with this problems for a couple of hours and I think it might not be possible to do this functionality now. I've encountered the same problem when trying to implement context menu's Inspect element button. Objects are serialized when being sent between shell and DevTools panel, thus we're losing theirs identity, and inspection API requires us to call it with object we want to inspect.

// this is now we call inspect API
chrome.devtools.inspectedWindow.eval(someHTMLElement);

// but during inspection of component we have to call 'stringify(getIntanceDetails)'
// which extracts data we want but serializes it to JSON, in case of HTMLElement we're 
// left with it's string representation
bridge.on('select-instance', id => {
  ...
  bridge.send('instance-details', stringify(getInstanceDetails(id)))
})

We're left with text 'HTMLElement' after serialization which is virtually useless.

Anyone has idea how to work around it?

EDIT: fixed typos

@ctf0
Copy link

ctf0 commented Dec 2, 2017

@posva is it possible as a first step for now to at least show the available refs under each component ?

@posva
Copy link
Member

posva commented Dec 2, 2017

I don't think listing only the names of the refs is enough to actually be useful 🙁 You'll end up just clicking on the element in the devtools and writing $vm.$refs in the console to properly inspect

@goyote
Copy link

goyote commented Dec 2, 2017

Would like to see the list of $refs as well.

@Akryum Akryum changed the title Feature request: inspect $refs Inspect $refs Jan 4, 2018
@hurrycaner
Copy link

👍

1099511627776 added a commit to 1099511627776/vue-devtools that referenced this issue Aug 17, 2018
@1099511627776
Copy link
Contributor

Hi, I've managed to make this feature but with some dirty hacks (from my point of view). Also I'm not very good at styling things so for now this feature looks like this http://nimb.ws/Ykq09X.
So is there some one that can look at screenshot and help me to make look it more pretty ?

@gabrielstuff
Copy link

Would be nice to see it land in the next version. 👏 @1099511627776

Akryum pushed a commit that referenced this issue Sep 16, 2018
* Probable fix for issue #450

* Removed unused code

* Added test components and some styles

* fixed eslint warnings

* npm run test now runs without errors

* fix: support refs lists

* test: e2e
@ctf0
Copy link

ctf0 commented Sep 19, 2018

@1099511627776 @Akryum when inspecting the component with the select btn the console will start logging msgs each time u move the mouse after, can u dbl check ?

Reason

function processRefs (instance) {
  if (Object.keys(instance.$refs).length === 0) {
    return []
  }
  console.log(instance.$refs) // the cause of the logging
  let refs = Object.keys(instance.$refs).map(key => Object(util["m" /* getCustomRefDetails */])(instance, key, instance.$refs[key]))
  return refs.length > 0 ? refs : []
}

version 5.0.0.b3

Update

untitled

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

No branches or pull requests

9 participants