我现在在做购物车,组件库都是用的elementUI,但是我发现elementUI的计数器你在输入框里面删除了数字他就为空我设置了最小值,所以我就想自己去判断一下并且修改值。
这是方法,因为后面可能还要计算价钱,所以想拿到这个索引,现在拿到了,但是我修改当前的他会把后面的全覆盖了,然后当前的没有显示,我看了vue的控制台,显示第一个已经被更改而且也设置了v-model,但是页面就是不展示
calcuationAmount(number) {
if (number === undefined || number === null) {
for (let i = 0; i < this.$data.goodsTable.length; i++) {
this.$set(this.goodsTable,i,{
img: this.goodsTable[i].img,
name: this.goodsTable[i].name,
quantity: 1,
unitPrice: this.goodsTable[i].unitPrice,
price: this.goodsTable[i].price
});
}
}
}
这是调用的
"scope">
<el-input-number
size="mini"
v-model="scope.row.quantity"
:min="1"
:max="9999"
@change="calcuationAmount(scope.row.quantity)">
el-input-number>
calcuationAmount这个方法里面的全部逻辑用个setTimeout函数包起来就可以了,不用设时间
值被改了,页面没更新 那就得用 set更新 。我看你也写了 。那说明 写的可能不对