Home  >  Article  >  Web Front-end  >  How vue+checkbox operates data binding, acquisition and calculation

How vue+checkbox operates data binding, acquisition and calculation

php中世界最好的语言
php中世界最好的语言Original
2018-04-12 16:59:552669browse

This time I will show you how to operate vue checkboxData binding and acquisition and calculation. What are the notes for vue checkbox operation data binding, acquisition and calculation, as follows This is a practical case, let’s take a look at it.

html

<input type=&#39;checkbox&#39; v-model=&#39;checkboxModel&#39; :value=&#39;z.coach_id+"-"+z.amount&#39; :i="dianji" @click="lll">

First CheckBox

<span><input type=&#39;checkbox&#39; v-model=&#39;checked&#39; v-on:click=&#39;checkedAll&#39;><span class="select-all">全选</span></span>

the second

Definition

return {
 dianji:'12',
 list: [],
 value:{},
 value1:{},
 checkAll: false,
 checkArr:[],
 checkboxModel:[],
 wodeshi:'0',
 checked:false
}
lll: function(){
 var self = this;
 var sum=0;
 setTimeout(function(){
 for(var x in self.checkboxModel){
 sum += parseInt(self.checkboxModel[x].split('-')[1])
 }
 self.wodeshi=sum;
 },0)
 // console.log(self.checkboxModel)
},
checkedAll: function() {
 var _this = this;
 if (this.checked) {//实现反选
 _this.checkboxModel = [];
 }else{//实现全选
 _this.checkboxModel = [];
 _this.list.forEach(function(z) {
 _this.checkboxModel.push(z.coach_id+'-'+z.amount);
 });
 }
 if(_this.checkboxModel.length==0){
 this.wodeshi=0;
 // console.log(_this.checkboxModel);
 }else {
 var self =this;
 var sum =0;
 for(var x in self.checkboxModel){
 sum += parseInt(self.checkboxModel[x].split('-')[1])
 }
 self.wodeshi=sum;
 }
},

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How NodeJS implements WebSocket function

What are the methods for nodeJs to connect to mysql

The above is the detailed content of How vue+checkbox operates data binding, acquisition and calculation. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn