[Vuejs]-$refs.myChildComponent is undefined although I see it in the console

0👍

$refs will only be populated after a component is mounted. So if you try to access a ref prior to that, for example from a created hook, it won’t be there.

There are other ways that a ref can be missing. For example, if you’re using v-if and the condition is false. In that case it isn’t sufficient to wait for the condition to become true, you would also need to wait for a rendering update to be performed and such updates are queued. In that case you’d either need to use the updated hook or a call to $nextTick.

Leave a comment