2

I have a Vue template wich recieves a json string as data:

<component data="{{ object.toJson() }}"></component>

object consists out of a name and an array of strings. I now have this in my

<template>    
    <ul>
      <li v-for="url in object.data['urls']">{{ url }}</li>
    </ul>
</template>

This however is giving errors on my linter and I was wondering why. This is exactly as according to the Vue examples posted on the documentation.

error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key

ThomasVdBerge
  • 7,483
  • 4
  • 44
  • 62

1 Answers1

5

You can add an index to your elements like so:

<template>    
    <ul>
      <li v-for="(url, index) in object.data['urls']" :key="index">{{ url }}</li>
    </ul>
</template>
Dylan
  • 1,681
  • 11
  • 16
  • [Please don't answer duplicate questions, you should mark them as such instead](https://stackoverflow.com/help/duplicates). – str Sep 26 '18 at 12:16