Comments are treated as a node in a development environment, and if there is more than one root node in a subcomponent, $el is bound to an empty node, so if there is an annotation in a subcomponent $el, it is not good to get the dom structure of the subcomponent
Version
3.2.31
Reproduction link
Steps to reproduce
point Hello world
What is expected?
hello world ->3
What is actually happening?
hello world->1
there is only one root Element in Comp.vue ,but it’s $el is not that root ,but a text node whose nodeType is 3
Yes, components can be fragments, in which case, they render two anchor text nodes around the actual nodes to simulate a single node parent. You can still access the subTree in $refs.myRef.$.subTree
and get the actual elements as well as other information there. This is also accessible directly with getCurrentInstance()
within the component.