I'm currently diving into Vue and tackling a project that heavily relies on vue.js. My goal is to display data in a component using a prop, and now I'm looking to implement a method to increment the quantity of a product.
Below is my code snippet:
<div v-for="(products, index) in products">
<mdc-layout-cell span="2" align="middle">
{{ products.product_barcode }}
</mdc-layout-cell>
<mdc-layout-cell span="2" align="middle">
{{ products.product_quantity}}
</mdc-layout-cell>
<i class="mdc-icon-toggle material-icons float-left"
aria-pressed="false"
v-on:click="incrementItem(index)">
add
</div>
Here's the relevant JS:
export default {
props: [
'products',
],
methods: {
incrementItem(index) {
let item = this.products[index];
this.products[index].product_quantity =
this.products[index].product_quantity + 1;
console.log(this.products[index].product_quantity);
},
}
While I can see the incremented value in the console, it doesn't seem to update in the corresponding row. How can I successfully increase the product_quantity value? Any guidance would be greatly appreciated.