Skip to content

Elements of array $refs keep the original order instead of the DOM order. #12074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
infinnie opened this issue May 13, 2021 · 1 comment
Closed

Comments

@infinnie
Copy link

Version

2.6.11

Reproduction link

https://codesandbox.io/s/focused-paper-3cqr1?file=/src/App.vue

Steps to reproduce

  1. Write the Vue code as below.
<template>
  <div id="app">
    <template v-for="item in array">
      <p :key="item" ref="test">{{ item }}</p>
    </template>
    <button type="button" @click="log">Log</button>
    <button type="button" @click="reorder">Reorder</button>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return { array: [1, 2, 3] };
  },
  methods: {
    log() {
      console.log(this.$refs.test.map((el) => el.getBoundingClientRect().top));
    },
    reorder() {
      this.array = [2, 1, 3];
    },
  },
};
</script>
  1. Call the reorder() method.

  2. Call the log() method after re-rendering.

What is expected?

An array is logged whose elements are in the order in which the corresponding elements appear in the document.

What is actually happening?

The logged array keeps the original order.

@infinnie infinnie changed the title Array $refs keep the original order instead of the DOM order. Elements of array $refs keep the original order instead of the DOM order. May 13, 2021
@infinnie
Copy link
Author

Duplicate of #4952

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant