[Vuejs]-Vuejs v2 – Delete item from array after computed reverse

0👍

You can pass barcode to delete function, then searching for matching barcode in this.barcodes array:

<div class="col-md-12" id="items" v-for="(barcode, index) in reversedOrderBarcodes">
    <div class="row">
        <div class="col-md-6" style="padding-top:7px;">
            <barcode :value="barcode | capitalize" format="code128" height="25" margin="0" width="1" font-size="12" text-margin="0">
            </barcode>
            <a href="#" @click.prevent="deleteBarcode(barcode)" style="position:absolute;right:0px;top:10px;">
                <span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span>
            </a>
        </div>
    </div>
</div>

and

methods: {
    deleteBarcode(barCode) {
       const barCodeIndex = this.barcodes.findIndex(code => code === barCode)
       if (barCodeIndex >= 0) {
         this.barcodes.splice(barCodeIndex, 1)
       }
    }
}   

-1👍

It’s not so vue or js task as math one:

deleteBarcode(index) {
    this.barcodes.splice(this.barcodes.length - 1 - index, 1);
}

Leave a comment