Subscribe on changes!

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

avatar
Mar 24th 2022

Version

3.2.31

Reproduction link

sfc.vuejs.org/

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

avatar
Mar 24th 2022

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.

avatar
Mar 24th 2022

But that makes difference between development and production because of there is no comment on production environment which can directly get the $el' dom structure and then use $refs.myRef.$.subTree will make error