Skip to content
This repository was archived by the owner on Aug 8, 2022. It is now read-only.

ref && v-for #357

Closed
JackShell2020 opened this issue Jan 14, 2021 · 2 comments · Fixed by #391
Closed

ref && v-for #357

JackShell2020 opened this issue Jan 14, 2021 · 2 comments · Fixed by #391

Comments

@JackShell2020
Copy link

官方文档

  • ref 与 v-for 一起使用时,你得到的 ref 将是一个数组,其中包含镜像数据源的子组件。(3.x的文档)
  • 当 ref 和 v-for 一起使用的时候,你得到的 ref 将会是一个包含了对应数据源的这些子组件的数组。(2.x的文档)

我的问题

<template>
  <div>
    <p v-for="item of arr" :key="item" :ref="item">{{item}}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: [
        'aaaa',
        'bbbb',
      ],
    };
  },
  mounted() {
    console.log(this.$refs.aaaa)
  },
};
</script>
  • ref=固定值 时: <p v-for="item of arr" :key="item" ref="myP">{{item}}</p>
    • 然后 console.log( this.$refs.myP ) 输出的应当是文档中说的数组
  • ref=不是固定值 时: <p v-for="item of arr" :key="item" :ref="item">{{item}}</p>
    • 然后 console.log( this.$refs.aaaa)
    • 在2.x版本中,输出的依然是数组(为什么)
    • 在3.x版本中,输出的确实当前节点(为什么)
@veaba
Copy link
Member

veaba commented Jan 14, 2021

@JackShell2020 看起来是 Vue 3.x 一个bug,建议你去官方 vue 3仓库中反馈该问题,中文文档仓库无法处理此类问题。

现发现 v3 英文版 已移除该段描述,我们将在后续的 v3 中文版本 中移除该段描述。

@veaba veaba closed this as completed Jan 14, 2021
@veaba veaba reopened this Jan 14, 2021
@veaba veaba self-assigned this Jan 14, 2021
veaba added a commit that referenced this issue Jan 28, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@veaba
Copy link
Member

veaba commented Jan 28, 2021

相关 PR #391

Jinjiang added a commit that referenced this issue Jan 31, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
fix: removed v-for for refs, close #357
ShroXd pushed a commit to ShroXd/docs-next-zh-cn that referenced this issue Jan 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants