vue实现全选,反选

1.example.vue

<template>
<table class="table-common">
<tr>
<th class="th1"><label for="selectAll"><input type="checkbox" v-model='checkAll' @click='checkedAll()' name="" id="selectAll" value="" />全选</label></th>
<th class="th2">维度名称</th>
<th class="th3">维度说明</th>
</tr>
<tr v-for="item in checkData">
<td ><input type="checkbox" name="" value="" v-model='item.isCheck' @change="singleSelect()"/></td>
<td class="right">item.text</td>
</tr>
</table>

</template>
<script>
  export default {
        name: 'design',
        data() {
        	return{
        		checkAll:false,
        		checkData:[
				{text:'haha',isCheck:false},
				{text:'hehe',isCheck:false},
				{text:'xixi',isCheck:false}
				]	
        	}
        },
        methods:{
        	//全选
        	 checkedAll() {
        	    for(var item=0;item<=this.checkData.length;item++){
        	 	this.checkData[item].isCheck = !this.checkAll;
        	     }
                 },
              //单选
	      singleSelect(){
		var selectData=this.checkData.filter(function(item){
			return item.isCheck==true;
		})
		selectData.length==this.checkData.length? this.checkAll=true:this.checkAll=false;
		},
			    
        }
   }
</script>                        

  

 

posted @ 2017-12-19 09:24  无花即无果  阅读(1616)  评论(0编辑  收藏  举报