最近用vant-ui+vue做了一个电商APP,在做购物车页面checkBox时发现,点击checkBox绑定的值变了,但页面没有同步刷新,最后的解决方案如下:
1.利用map返回新数组
this.cartInfo = this.cartInfo.map( item => {
item.isCheck = this.orderChecked;
item.goods = item.goods.map(item2 => {
item2.isCheck = this.orderChecked;
return item2;
})
return item;
})
2.vue的set方法
this.cartInfo.forEach( (item,index) => {
item.isCheck = this.orderChecked
item.goods.forEach(item2 => {
item2.isCheck = this.orderChecked
})
this.$set(this.cartInfo,index, item)
})
上面是全选按钮。点击店铺选择店铺下的所有商品如下:
shopCheck(isCheck,index) {