[Vuejs]-Vue: how to delete item from api

0👍

The method splice takes the index of the item in the array and delete count. Take a look at the documentation here:

Array.prototype.splice documentation

What you can do instead of using splice (and a better practice of doing this) is to reset the selectedIndex in your data with a filtered version:

this.selectedIndex = this.selectedIndex.filter(item => item !== categories._id)

But what I understood from the code, you want to remove all categories, under the posts object. In this case, instead of mutating selectedIndex you have to set the this.posts.categories to an empty array in your RemoveAllSelected function:

RemoveAllSelected(categories) {
   this.posts.categories = []
}

0👍

   @click="RemoveAllSelected(index)"

@click method just pass index and slice item based on index on your RemoveAllSelected method this.posts.categories.slice(index, -1)

Leave a comment