Skip to content

Inconsistent element reuse in v-for when using key #4834

@mzgajner

Description

@mzgajner

Vue.js version

2.1.10

Reproduction Link

JSFiddle

Steps to reproduce

  1. Start with an array of items and slice a subset from that array.
  2. Using v-for, loop through that subset in a template and render some elements. Make sure you set :key props on those elements and pass consistent IDs to track which element belongs to which item.
  3. Change the subset by changing the position where it is sliced from the array of items.

What is Expected?

If I understand how :key is supposed to work, items should be matched to elements based on their unique id. When items are updated (some added/removed, some left intact), the ones that remain should stay in the same elements for animation purposes.

What is actually happening?

The reuse of elements is inconsistent. In the demo fiddle, when clicking up, a transition is triggered, which means the items remained in the same elements as expected. But clicking down instantly changes all values, which hints that new elements were created.

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