undefinedfix
Sign in

V-IF console error

izy edited in Mon, 21 Mar 2022

图片描述

(the key value has been bound to the for loop) the console reported such an error. How can I solve this problem

5 Replies
user151860
commented on Mon, 21 Mar 2022

It is estimated that your project uses eslint check and also has V-for. Just add a: key

<div v-for="(item, index) of items" :key="index">

After the problem is revised

  1. There is no problem with the two
  2. There is no problem with key

Template can't use: key, so I don't think the error of the main code is the error of the screenshot. After I use: key for template, the following error appears

  • <template> cannot be keyed. Place the key on real elements instead.

It's right to change it to div or set a layer of div in the template

Bjorn
commented on Mon, 21 Mar 2022

Look at the error report. Let's add: key

Silverfern
commented on Mon, 21 Mar 2022

Template is replaced with div and other tags. You can hover to the error reporting place, and the error message will be displayed

Donovan
commented on Mon, 21 Mar 2022

The key value is repeated. The following table of your two loops is index. The second loop uses the index of the first loop. The key value may be undefined, which is equivalent to the unbound key value

pazhitnov
commented on Tue, 22 Mar 2022

Try using a different key for the two loops. For example, change the second one to key ='key '

lock This question has been locked and the reply function has been disabled.