【问题标题】:Vue js [Vue warn]: Duplicate keys detected:Vue js [Vue 警告]:检测到重复键:
【发布时间】:2022-01-09 21:12:19
【问题描述】:

您好,我知道是什么问题,但我不知道如何解决。请帮忙。

我正在生成输入字段和文本区域字段,所以我有 2 个 v-fors(我会和第三个)

<div v-for="(textarea, textareaId) in blog.textareas" :key="textareaId">
<div v-for="(sectionTitle, sectionTId) in blog.sectionTitles" :key="sectionTId">

blog:{
            blogTitle: '',
            images: [
                {
                    imagesId: 0,//this was called id
                    name: ''
                }

            ],
            sectionTitles:[
                {
                    sectionTId: 0,//this was called id
                    title: ''    
                },
                
            ],
            textareas: [
                {
                    textareaId:0, //this was called id
                    text: ''
                },

            ]

        },

我尝试将 id 更改为不全为三个 0,但每次我输入相同的数字时都会收到警告:key="id"

Duplicate keys detected: '1'
Duplicate keys detected: '2'

等等。

【问题讨论】:

  • :key="'textarea_'+textareaId" 和 sectionTitles :key="'section_'+sectionTId"
  • 感谢工作。
  • @Radeanu 填写答案,以便问题的作者接受。

标签: vuejs2 duplicates key v-for


【解决方案1】:
:key="'textarea_'+textareaId" and for sectionTitles :key="'section_'+sectionTId"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-17
    • 2018-06-07
    • 2021-12-16
    • 2020-06-10
    • 2020-05-28
    • 2020-12-25
    • 1970-01-01
    • 2017-09-09
    相关资源
    最近更新 更多