cydysm
2019-04-30 13:37:31 +08:00
供参考
命名是 Vue 的 example
```
<div id="demo">
<input type="checkbox" id="jack" value="1" v-model="checkedNames">
<label for="jack">10</label>
<input type="checkbox" id="john" value="2" v-model="checkedNames">
<label for="john">10</label>
<input type="checkbox" id="mike" value="3" v-model="checkedNames">
<label for="mike">20</label>
<br>
<span>Checked names: {{ checkedNames }}</span>
<br/>
<span>total: {{ total }}</span>
</div>
<script>
var _init = new Vue({
el: '#demo',
data: {
checkedNames: [],
price: [10,10,30],
total: null,
},
watch:{
checkedNames(newValue) {
this.total = null;
newValue.forEach((value,index)=>{
this.total += this.price[index];
})
}
}
});
<script/>
```