// 以下代码实现全选多选反选取消选择,具体实现代码? <div class="box"> <div class="list"> <div class="list-head"> <div class="check-box"> <el-checkbox v-model="checkAll">全选该页</el-checkbox> </div> <div class="title"> 需审核共<span class="red">15篇</span>内容 </div> <div class="list-btn"> <el-button size="medium" class="seachBtn">批量通过</el-button> </div> </div> <div class="list-box"> <div class="cell"> <div class="list-box-check"> <el-checkbox></el-checkbox> </div> <div class="text"> <div class="name">ZCH3021 财联社3月1日早报(周三)</div> <div class="p"> <div class="reason"> <span>过滤原因</span> <span>高敏感</span> </div> <div class="warehousing-time"> <span>入库时间</span> <span>2023-04-10 16:25:50</span> </div> </div> </div> </div> <div class="cell"> <div class="list-box-check"> <el-checkbox></el-checkbox> </div> <div class="text"> <div class="name">ZCH3021 财联社3月1日早报(周三)</div> <div class="p"> <div class="reason"> <span>过滤原因</span> <span>高敏感</span> </div> <div class="warehousing-time"> <span>入库时间</span> <span>2023-04-10 16:25:50</span> </div> </div> </div> </div> </div> </div> <div class="content"> </div> </div>
时间: 2023-08-13 17:44:40 浏览: 190
以下是实现全选、多选、反选和取消选择的具体代码:
1. 数据部分
```
data() {
return {
checkAll: false, // 是否全选
checkboxList: [] // 多选列表
}
},
```
2. 全选功能
```
methods: {
handleCheckAllChange(val) { // 全选或取消全选
this.checkboxList = val ? this.listData : [];
}
}
```
```
<el-checkbox v-model="checkAll" @change="handleCheckAllChange">{{ checkAll ? '取消全选' : '全选该页' }}</el-checkbox>
```
3. 多选功能
```
methods: {
handleCheckboxChange() { // 多选
const checkedCount = this.checkboxList.length;
this.checkAll = checkedCount === this.listData.length;
}
}
```
```
<el-checkbox v-model="checkboxList" @change="handleCheckboxChange"></el-checkbox>
```
4. 反选功能
```
methods: {
handleReverseSelection() { // 反选
this.checkboxList = this.listData.filter(item => !this.checkboxList.includes(item));
this.checkAll = this.checkboxList.length === this.listData.length;
}
}
```
```
<el-button size="medium" @click="handleReverseSelection">反选</el-button>
```
5. 取消选择功能
```
methods: {
handleClearSelection() { // 取消选择
this.checkAll = false;
this.checkboxList = [];
}
}
```
```
<el-button size="medium" @click="handleClearSelection">取消选择</el-button>
```
阅读全文