0👍
Having multiple steps of finding value with combination of for
loop and if
statement reduces readability and code predictability. In addition, invoking array mutating method splice
may not trigger reactive update of this property.
I’d suggest to use filter and re-assign selectedItems_
inside itemDeleted
method as follows:
public itemDeleted(item) {
this.selectedItems_ = this.selectedItems_.filter(selectedItem => selectedItem.key !== item.key)
this.$emit('itemdeleted', item);
}
This way, after method execution, selectedItems_
will consist of all previous items except the one provided as an argument to the method and all dependent properties will be re-computed.
Source:stackexchange.com