首先在tree里定义ref
<el-input
placeholder="输入关键字进行过滤"
v-model="filterText">
</el-input>
<el-tree
ref="treeFilter"
:filter-node-method="filterTreeNode"
>
<el-tree/>
setup(){
let treeRef = ref<any>(null);
let filterText=ref("")
const filterTreeNode = (value: string, data: any) => { if (!value) return true; return data.name.indexOf(value) !== -1; };
watch(
() => filterText, (newValue, oldValue) => { treeRef.value.filter(newValue); }
)
return{
filterText,
filterText,
filterTreeNode
}