Vuejs reported an error

the error is as follows:
clipboard.png

clipboard.png

would you like to know why this is because the DOM node cannot be found?

Sep.23,2021

check that this ref, is not accessible at this time before the component is mounted. For example, if you call this function in created,beforeMount, you will get an error. If you call it in mouted, you should pay attention to whether it is directed to the child component, and if so, there is no guarantee that the child component is mounted. If you have to use it in these stages, it is recommended to add nextTick.

clipboard.png


ref is used to register reference information with elements or subcomponents. The reference information will be registered on the $refs object of the parent component. If used on ordinary DOM elements, the reference points to the DOM element; if used on subcomponents, the reference points to the component instance

<!-- `vm.$refs.p` will be the DOM node -->
<p ref="p">hello

<!-- `vm.$refs.child` will be the child component instance --> <child-component ref="child"></child-component>

-excerpt from the vue official website
so did you register ref attribute

on the subcomponent?
Menu