我对 vue 很陌生,正在处理一个基于 vue.js 的任务。我正在使用道具在组件中显示我的数据。现在我想添加一个方法来增加产品的数量。
这是我的代码:
<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>
Run Code Online (Sandbox Code Playgroud)
这是我的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);
},
}
Run Code Online (Sandbox Code Playgroud)
我可以在控制台中看到增加的值,但相应行中的值没有增加。我怎样才能增加product_quantity的值?任何帮助将非常感激