[Vuejs]-Assign an ID in each object of array

1👍

If I understood you correctly try with index:

new Vue({
  el: '#demo',
  data() {
    return {
      items: [
        { color: 'blue', size: 'large', height: 'tall' },
        { color: 'green', size: 'medium', height: 'short' },
        { color: 'purple', size: 'small', height: 'average' }
      ]
    }
  },
  methods: {
    del(i) {
      this.items.splice(i, 1)
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  <div v-for="(item, i) in items" :key="i">
    <div>{{ i+1 }} - {{ item.color }}</div>
    <button @click="del(i)">delete</button>
  </div>
</div>

Leave a comment