Skip to content Skip to sidebar Skip to footer

Splice Does Not Delete The Current Element

I am trying to delete the current item on click, but when i run it it deletes only the last item. I'm going crazy, on another component I did the same thing and it worked...I don't

Solution 1:

splice mutates the array which tries to mutate the prop, but in vue we cannot change props from child component, so you should emit an event to the parent component with the index as payload :

deleteTime(index) {
       console.log(index);
       this.$emit("delete-time",index)
     },

in parent :

   <child @delete-time="onDeleteTime" .../>

...

methods:{
 onDeleteTime(index) {
      
       this.hour.splice(index, 1);
     },
}

Post a Comment for "Splice Does Not Delete The Current Element"