<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
</head>
<body>
<div id="contend">
<table>
<thead>
<th><input type="checkbox" v-model="allCheck"></th>
</thead>
<tbody>
<tr v-for="(itme,index) in arr" :key="index">
<td><input type="checkbox" v-model="itme.state"></td>
<td>{{itme.name}}</td>
<td>{{itme.price}}</td>
</tr>
</tbody>
</table>
总价:{{allp}}
</div>
</body>
<script>
new Vue({
el: '#contend',
data: {
arr: [
{
name: '苹果',
price: '20',
state: false
},
{
name: '橘子',
price: '30',
state: false
},
{
name: '桃子',
price: '25',
state: false
}
],
allp: ''
},
computed: {
allCheck: {
get() {
let picke = 0
this.arr.forEach(item => {
if (item.state) {
picke += Number(item.price)
}
this.allp = picke
})
return this.arr.every((item) => item.state)
},
set(a) {
return this.arr.forEach(item => (item.state = a));
}
},
}
})
</script>
</html>
vue购物车
最新推荐文章于 2025-04-24 17:20:34 发布