<div class="half-transfer">
<div class="el-transfer-panel">
<el-checkbox v-model="selectAll" @change="handleSelectAll">全部el-checkbox>
<el-input v-model="searchInput" placeholder="请输入搜索内容" clearable @clear="clearSearch">el-input>
<div class="el-transfer__list">
:default-expand-all="true"
:default-checked-keys="checkedKeys"
:filter-node-method="filterNode"
@check="handleCheckChange"
import { ref, reactive, watch, nextTick } from 'vue';
import { ElTree, ElCheckbox, ElInput } from 'element-plus';
const searchInput = ref('');
const checkedKeys = ref([]);
const treeData = reactive([
{ key: 11, label: '子选项11' },
{ key: 12, label: '子选项12' },
{ key: 13, label: '子选项13' },
{ key: 21, label: '子选项21' },
{ key: 22, label: '子选项22' },
{ key: 23, label: '子选项23' },
const selectAll = ref(false);
const treeRef = ref(null);
watch(searchInput, (val) => {
treeRef.value.filter(val);
const filterNode = (value, data) => {
return data.label.includes(value);
const clearSearch = () => {
const handleSelectAll = (checked) => {
checkedKeys.value = getAllNodeKeys();
treeRef.value.setCheckedKeys([]);
const getAllNodeKeys = () => {
const traverse = (nodes) => {
for (const node of nodes) {
if (node.children && node.children.length > 0) {
const handleCheckChange = (data) => {
checkedKeys.value = data.checkedKeys;
console.log(treeRef.value.getCheckedKeys())
const nodes = treeRef.value.root.childNodes;
const allChecked = nodes.every((node) => node.checked);
selectAll.value = allChecked;
border: 1px solid #dcdfe6;
.el-transfer__list .el-checkbox-group {
.el-transfer__list .el-checkbox {
.el-transfer__list .el-checkbox:last-child {
.el-transfer__list .el-scrollbar {
background-color: #f5f7fa;