<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>vue</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js">
</script>
<style>
</style>
</head>
<body>
<h1>购物车</h1>
<div id="app-one">
<ul>
<li v-for="data in datalist">
<input type="checkbox" v-model="checkshopcar" :value="data">
{{data}}
</li>
</ul>
<p>{{checkshopcar}}</p>
<p>总额{{sum}}</p>
</div>
</body>
</html>
<script>
var vm = new Vue({
el: "#app-one",
data:{
datalist:[
{
name:"衣服aaa",
price:10,
number:2
},
{
name:"袜子aaa",
price:20,
number:3
},
{
name:"外套aaa",
price:100,
number:2
},
],
checkshopcar:[]
},
computed:{
sum(){
var sum = 0;
this.checkshopcar.forEach((item,index)=>{
sum+=item.price*item.number;
})
return sum;
}
}
});
</script>
网友评论