Elias
Elias

Reputation: 155

Set an Pseude/autogenerated :key for v-for element vue.js

i need to set a pseude/autogenerated :key for v-for elements because the ids of the items could be duplicate.

i tried this:

<my-component v-for="items in item" v-bind:key="getPseudoIds()">

...

props:{
'id' : {
  default: 0,
  type: Number,
}

...

 getPseudeIds(){
   return this.id++;
},

but i always get a

Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "id"

and if i declare id as data i get a infinite loop error

Upvotes: 0

Views: 101

Answers (1)

Maximilian Stolz
Maximilian Stolz

Reputation: 459

is the key relevant? You could use the index as key

<my-component v-for="(item, index) in items" :key="index">

Upvotes: 2

Related Questions