javascript - 当我更改对象中的某些内容时,我在插值中的值不会更新
问题描述
我有这个v-for
:
<tr v-for="(product, index) in products" v-bind:key="products.id">
<div v-on:click="decrementQtd(index)" class="action-qtd-button-left">
<strong>-</strong>
</div>
<div class="div-input-qtd">
<input v-model="product.quantity" class="input-qtd-cart" type="text">
</div>
</tr>
在我的脚本中:
methods: {
decrementQtd: function (index) {
this.products[index].quantity--
}
如果我做了一个console.log(quantity)
递减好的,但插值中的值没有更新,我该如何解决这个问题?
解决方案
我根据这段代码制作了一支笔,它工作正常。单击 - 正在减少文本框中的数量。请在此处查看: https ://codepen.io/v08i/pen/KKwOgaw
<div id="app">
<table>
<tr v-for="(product, index) in products" v-bind:key="product.id">
<td><div v-on:click="decrementQtd(index)" class="action-qtd-button-left">
<strong>-</strong>
</div>
<div class="div-input-qtd">
<input v-model="product.quantity" class="input-qtd-cart" type="text">
</div>
</td>
</tr>
</table>
</div>
var app = new Vue({
el: '#app',
data: {
name: 'Jonathan',
products: [
{
id: 1,
quantity: 10
},
{
id: 2,
quantity: 15
},
{
id: 3,
quantity: 25
}
]
},
methods:{
decrementQtd: function (index) {
this.products[index].quantity--
}
}
})
注意:我还在 tr 中添加了 td,如果删除它们,代码将停止工作。
推荐阅读
- typescript - TypeScript 类型上不存在属性“加载”?
- powershell - Powershell命令根据过滤器从多个文件夹中获取所有文件
- python - 测试用例使 os.getuid() 和 os.geteuid() 返回不同的结果
- matlab - 查找与“knnsearch”matlab函数的一一对应关系
- postgresql - PostgreSQL 中内联 SQL 函数调度的解决方法
- python - 如何在任何条件下通过另一个值设置熊猫值
- c# - .Net Core 3 WebAPI 在随机使用几天后变得无响应
- firebase - Firestore - 如果大于零,则减少数字
- kedro - Jupyter Notebook 中缺少 Kedro 上下文和目录
- wordpress - WooCommerce 如何更改单个产品属性的顺序 - 交换它们的位置