Skip to content

Refs incorrect when using v-for and combining components and elements #5997

@floorish

Description

@floorish

Version

2.3.4

Reproduction link

https://jsfiddle.net/floorish/7td2offb/

Steps to reproduce

  • Parent with dynamic components, referenced by ref: <component :is="child.type" v-for="child in children" :key="child.id" ref="children"></component>
  • Multiple child.types where one of them uses a loading component: <loading v-if="isLoading"></loading> <div v-else>Child B ready</div>
  • In Child switch isLoading from true to false after a timeout/async call

What is expected?

parent.$refs.children equals the displayed child components

What is actually happening?

parent.$refs.children only includes the child component that has the loading mechanism


This is very much an edge case, but it took me a while to figure out any solutions. Most trivial solution is to wrap the Child template in another <div>, but AFAIK the <div v-if="val"></div> <div v-else></div> construct in the root of a template is supported in Vue (there is always a single root element).

Other solutions are provided in reproduction link.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions