[Vuejs]-Vue js – vsCode – I get an error when I use v-for?

4👍

You need to provide key in the v-for tag.

<app-card v-for="item in cards" :key="item.id"></app-card>

or

<app-card v-for="(item,index) in cards" :key="index"></app-card>

1👍

As error saying itself, :key directive is missing as it should be there while working with v-for.

You don’t need a key attribute in order to use v-for, but it’s a good practice, that’s why editor intelligence is telling you to add.

Please have a read of the official documentation of vue.js regarding maintaining state while using v-for.

Leave a comment