<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vue</title>
<script src="../vue.js"></script>
</head>
<body>
<div id="main">
<ul>
<li v-for="data in dataList">
<input type="checkbox" v-model="checkArr" :value="data">
{{data}}
</li>
</ul>
total:{{calc()}}
</div>
<script>
new Vue({
el: '#main',
data: {
checkArr: [],
dataList: [
{id:1, salary: 11},
{id:2, salary: 22},
{id:3, salary: 33},
{id:4, salary: 44}
]
},
methods: {
calc() {
let sum = 0;
for(let index = 0; index < this.checkArr.length; index++)
{
sum += this.checkArr[index].salary;
}
return sum;
}
}
})
</script>
</body>
</html>
双向数据绑定实现简单列表计算
最新推荐文章于 2020-08-07 23:31:03 发布