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="" />全选</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>
以上是 vue实现全选,反选 的全部内容, 来源链接: utcz.com/z/380786.html