watch:{
shopData:{
handler(val,oldVal){
let a_val = 0
let a_count = 0
let a_price = 0
let a_salePrice=0
val.forEach((item)=>{
item.allPrice = (item.count - 0) * (item.price - 0);
a_val += (item.allPrice - 0)
a_count += (item.count- 0)
a_price += (item.price- 0 )
a_salePrice+=(item.rollbackCount-0)
})
a_val = a_val.toFixed(2)
a_count = a_count.toFixed(0)
a_price = a_price.toFixed(2)
a_salePrice=a_salePrice.toFixed(2)
this.allProductPrice = a_val // 满减需注释
this.allNumber = a_count
this.salePrice = a_price
this.salePrice= a_salePrice
},
deep: true 深度监听
},
eidtshopDataf(rowData){
this.shopData=rowData;
},
不适用watch的话,直接函数内计算fixed(2) 连续点数据会有误差
handler返回变化后的数据,watch第一次加载不执行,数据有变化才会执行,如果需要页面加载完毕执行,那就加上immediate:true
与deep
同级
监听对象或者数组的写法
写法watch:{数组或者对象:{handler(val,oldval{},deep:true)}}
/* 监听对象中属性的写法'obj.属性':{handler(val,oldval){}} */