vue2.0中vue-cli实现全选、单选计算总价格的实例代码

2020-06-12 21:10:20易采站长站整理

methods:{

currClick:function(item,index){

var _this = this;

if(typeof item.checked == 'undefined'){

this.$set(item,'checked',true);

let total = item.price*item.count;

this.totalPrice.push(total);

console.log(this.totalPrice);

}else{

item.checked = !item.checked;

if(item.checked){

this.totalPrice = [];

this.lists.forEach(function(item,index){

if(item.checked){

let total = item.price*item.count;

_this.totalPrice.push(total);

}

});

}else{

this.totalPrice = [];

this.lists.forEach(function(item,index){

if(item.checked){

let total = item.price*item.count;

_this.totalPrice.push(total);

}

});

}

}

}

}

}

</script>

<style>

tr td{

width:200px;

background: #eee;

padding:10px 0;

}

</style>

效果: